Eclpse CDT gtest setup error:cannot find -lgtest - eclipse

I follow this post
to setup gtest 1.7 on eclipse cdt 8.2.1.but got this errors:
....test/AllTests.bc src/Test.bc -lgmock -lgtest -lpthread -lstdc++
/usr/bin/ld: cannot find -lgmock
/usr/bin/ld: cannot find -lgtest
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Info: Parallel threads used: 3
By the way,there is some change from gtest 1.5 to 1.7,I actually make link like this:
sudo ln -s lib/.libs/libgtest.a /usr/lib/libgtest.a
As you can see,libgtest is under gtest1.7/lib/.lib(the second hidden dir) not gtest1.7/lib.
so what did I do wrong?

You appear to have attempted to make symbolic links to libgtest.a
and libgmock.a by using the commands:
sudo ln -s lib/.libs/libgtest.a /usr/lib/libgtest.a
sudo ln -s lib/.libs/libgmock.a /usr/lib/libgmock.a
from the console in /your/path/to/gtest-1.7.0 and /your/path/to/gmock-1.7.0
respectively.
If you open /usr/lib in your file manager, find the links libgtest.a
and libgmock.a and exam their properties, I believe you will find that
these links are broken, and that is why the linker cannot find them
in your project. Your ln commands give relative paths to their targets,
but absolute paths are needed.
If so, delete the broken links and recreate them with the commands:
sudo ln -s /full/path/to/gtest-1.7.0/lib/.libs/libgtest.a /usr/lib/libgtest.a
sudo ln -s /full/path/to/mock-1.7.0/lib/.libs/libgmock.a /usr/lib/libgmock.a
E.g on my system /full/path/to/ = /home/imk/develop/
Then I think your build will work.
However, creating these symbolic links in /usr/lib slightly taints your
system installation. It would be better to create them in /usr/local/lib.
Or even simpler, you can just add these static libraries to the object files
for your project linkage:
In Eclipse, navigate your project -> Properties -> C/C++ build
-> Settings -> your compiler Linker -> Libraries and delete gmock.a, gtest.a
Immediately under Libraries you find Miscellaneous. There, in
Other objects, add:
/full/path/to/libgtest.a
/full/path/to/libgmock.a
All these suggestions have worked for me.

Related

example.c:1:22: fatal error: postgres.h: No such file or directory

I'm trying to create my own function (using C) in postgres for which I'm referring this doc: http://www.linuxgazette.cz/139/peterson.html
For compiling - I'm referring: Section 33.9.6 . But, when I run below command:
cc -fpic -c example.c
I get this error:
example.c:1:22: fatal error: postgres.h: No such file or directory
#include "postgres.h"
^
compilation terminated.
I have also installed postgresql-server-dev-all package and tried with the solution provided in this link: How to fix 'postgres.h' file not found problem?
Nothing working for me. Please let me know how I can have postgres.h file.
I'm using postgres-12 on centos -7.
First: If you didn't install PostgreSQL from source, make sure that you installed the headers, which are in the -devel package.
If the problem persists even with the headers installed, the reason is that you forgot to tell the compiler where to look for header files:
cc -fpic -I /location/of/postgres/include -c example.c
To find that location, you can use pg_config:
pg_config --includedir
There is a similar --libdir option to show the library path for when you link the executable.
for ubuntu: apt-get -y install postgresql-server-dev-13 after apt-get -y install postgresql-13

gcc49 on Fedora 27: /usr/bin/ld: cannot find -lgcc_s

I am using the davidva/gcc49 copr, on Fedora 27.
When I try to compile after running source /usr/bin/gcc49 as the copr webpage describes, I get this error:
/usr/bin/ld: cannot find -lgcc_s
After learning about how the flag -l works for gcc, I learned it is looking for library gcc_s. I found it in /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64, which sounds like the right spot for it to be. Why is it not linking? Do I need to add a directory to a library path? If it's LDFLAGS, it's already there because of the file I sourced:
export LDFLAGS="-L/opt/gcc-$gver/$lib/gcc/$gcc_target_platform/$lib/"
What do I need to do to get gcc 4.9 on Fedora 27 to find its library file which is clearly in the LDFLAGS directory?
The problem is that the libgcc_s.so file is in the wrong directory! Just symlink to it in the 4.9.3 directory:
pushd /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/4.9.3
sudo cp -p ../lib64/libgcc_s.so.1 .
sudo ln -s libgcc_s.so.1 libgcc_s.so
popd
I guess the /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64 directory was supposed to be included in any LDFLAGS parameter, and that might be a weakness of the build process I was using and not the gcc 4.9 package.
Putting this file and appropriately-named symlink in the 4.9.3 directory allows my build process to complete successfully.
Reference: https://bgstack15.wordpress.com/2018/02/01/gcc-4-9-for-fedora-27/

How to force MATLAB 2016a to use gcc-4.7.x instead of the one I have (gcc-5.4.1)?

There are some posts about this for the older releases of MATLAB, but they don't seem to work for R2016a.
I'm trying to install MatConvNet on Ubuntu 16.04. When I run the vl_compilenn command as described here, it gives me a warning as follows:
Building with 'gcc'.
Warning: You are using gcc version '5.4.1'. The version of gcc is not supported.
The version currently supported with MEX is '4.7.x'. For a list of currently supported
compilers see: http://www.mathworks.com/support/compilers/current_release.
I have already installed gcc-4.7 and g++-4.7 using apt-get install gcc-4.7 g++-4.7. How can I force MATLAB to use these versions and not the default ones?
Few hints, not a complete tutorial how to do it.
Probably the simplest would be to edit the MATLAB's Mex XML configuration file:
mex -setup C
cc = mex.getCompilerConfigurations('C', 'Selected')
edit(cc.MexOpt)
The mex setup usually creates a copy in your home folder (~/.matlab/<version>/mex_C_glnca64.xml), so you should be able to edit it without root.
There you probably need to change the section:
<GCC>
<cmdReturns name="which gcc" />
</GCC>
which I guess searches for the location of the gcc command to your gcc version and assigns it to the $GCC variable. Plus you can change the version name in the header.
Additionally you need to do the same for the C++ language.
This works with R2016b:
Install the required GCC version with apt install (gcc-4.9 and g++-4.9 in my case).
Create a bin folder in your home, i.e. ~/bin.
Create the following links with ln:
ln -s /usr/bin/gcc-4.9 ~/bin/gcc
ln -s /usr/bin/g++-4.9 ~/bin/g++
If using CUDA, create a file called nvcc in the ~/bin folder, with the following contents (don't forget to make it executable: chmod +x ~/bin/nvcc):
Contents:
#!/bin/sh
exec /usr/lib/nvidia-cuda-toolkit/bin/nvcc -ccbin gcc-4.9 "$#"
If necessary replace /usr/lib/nvidia-cuda-toolkit/bin/nvcc with the correct location of the nvcc binary.
Open MATLAB and follow the instructions for compiling MatConvNet.

updated libraries are incompatible

OS -> ubuntu 11.10( Yes,its quite old version but unfortunately we cant upgrade it)
Updated driver -> ftdi driver from libftd2xx.so.1.1.1 to libftd2xx.so.1.1.12
IDE -> ecillpse
Issue -> failed to include update library
Error ->
/usr/bin/ld: skipping incompatible /usr/local/lib/libftd2xx.so when
searching for -lftd2xx
/usr/bin/ld: skipping incompatible
/usr/local/lib/libftd2xx.a when searching for -lftd2xx
Overview:
I have embedded system which uses ftdi chip. I have to include some new functions in my coding so for that reason I have upgraded the library . Below are the following steps I have followed
tar xfvz libftd2xx1.1.12.tar.gz
cd build/arm926
cp lib* /usr/local/lib
Copies the libraries to a central location.
chmod 0755 /usr/local/lib/libftd2xx.so.1.1.12
ln -sf /usr/local/lib/libftd2xx.so.1.1.12 /usr/local/lib/libftd2xx.so
Building the shared-object examples.
cd examples
make -B ( I followed these steps as written in their documentation but no idea why I did)
Run ldconfig
sudo ldconfig -l /usr/local/lib/libftd2xx.so.1.1.12
Run file libftd2xx.a
o/p libftd2xx.a: current ar archive
May you guys please help me or point me where I am committing mistake .
Thanks a lot
Sorry guys , I was following instructions from ftdi coument and instead of going into i386 directory , i went into arm986 .

command-line library build fails with linker error

I am getting a library not found error building GraphViz current release (June 7 2012) with Xcode 4.3 using a script. I may have made mistakes updating build scripts from other people's successful recipes for the new location of Xcode4.3 and the developer tools in the Applications folder.
ld: library not found for -lcrt1.10.6.o
(doing this from memory so exact number on the CRT lib may be wrong)
Am also a little lost also how I would incorporate this into an Xcode build in the IDE. I am a very experienced programmer but having trouble finding my way around Xcode 4 at times. (Decades of Visual Studio et al).
I have copied the instructions from this earlier question and adapted
#!/bin/sh
# For iPhoneOS, see http://clang.llvm.org/ for options
export DEV_iOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
# was /Developer/Platforms/iPhoneOS.platform/Developer
export SDK_iOS=${DEV_iOS}/SDKs/iPhoneOS5.1.sdk
export COMPILER_iOS=${DEV_iOS}/usr/bin
export CC=${COMPILER_iOS}/clang
export CXX=${COMPILER_iOS}/clang++
export LDFLAGS="-arch armv7 -pipe -Os -gdwarf-2 -mthumb -isysroot ${SDK_iOS}"
export CFLAGS="${LDFLAGS}"
export OBJCFLAGS="${LDFLAGS}"
export CXXFLAGS="${LDFLAGS} -fvisibility-inlines-hidden"
export LD=${COMPILER_iOS}/ld
export CPP=${COMPILER_iOS}/clang
export AR=${COMPILER_iOS}/ar
export AS=${COMPILER_iOS}/as
export NM=${COMPILER_iOS}/nm
export CXXCPP="${COMPILER_iOS}/clang++"
export OBJC=${COMPILER_iOS}/clang
export RANLIB=${COMPILER_iOS}/ranlib
./configure \
--build=arm-apple-darwin11 \
--host=arm-apple-darwin11 \
--disable-dependency-tracking \
--enable-shared=no \
--enable-static=yes \
--enable-ltdl=no \
--enable-swig=no \
--enable-tcl=no \
--srcdir=${GVROOT} \
--with-codegens=no \
--with-cgraph=no \
--with-graph=yes \
--with-expat=no \
--with-fontconfig=no \
--with-freetype2=no \
--with-ipsepcola=yes \
--with-libgd=no \
--with-quartz=yes \
--with-visio=yes \
--with-x=no
The compiler normally uses crt1.o combined with crt[i/n].o and crt[begin/end].o to support the constructors and destructors (functions called before and after main and exit).
This error could be caused by this missing library file for the specific deployment target.
First, do some investigation, like:
list all your deployment targets:
ls -la /Developer/SDKs
and find which crt1 libraries do you have for which environment
find /Developer/SDKs -name crt1\*
You could see something like:
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.10.5.o
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.o
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.5.o
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.o
So as you can see, crt1.10.6.o is missing for MacOSX10.5.
Solution 1:
You can solve that by creating the link to the missing file pointed to the other environment, or you could change your deployment target.
E.g.
ln -s /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o /Developer/SDKs/MacOSX10.5.sdk/usr/lib/
Also this could be caused, that you have different gcc installed in your system. See:
which gcc;
xcrun -find gcc;
brew list | grep gcc; brew list gcc47
Solution 2
So when you're compiling using make, you can actually specify the right compiler by CC variable. E.g.
CC=/path/to/gcc-3.4 make
Solution 3
What you can also try is specifying the right target deployment environment variable for gcc, by executing the following lines:
export MACOSX_DEPLOYMENT_TARGET=10.5
export C_INCLUDE_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/include
export LIBRARY_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/lib
If this works, then you can add above lines to your shell profile (~/.profile) to make the change permanent.
How to test
Create the example conftest.c file with the following code:
#ifdef __GNUC__
yes;
#endif
And try to compile it via:
gcc conftest.c
cc conftest.c
cc conftest.cc conftest.c
Troubleshooting
To see which exactly what file is missing, try to debug it using dtruss, e.g.:
sudo dtruss -f gcc conftest.c 2>/dev/stdout | grep crt
You should see something like:
12426/0xb4e3b: stat64("/Developer/usr/lib/gcc/i686-apple-darwin10/4.2.1/crt1.10.6.o\0", 0x7FFF5FBFE780, 0xB) = -1 Err#2
So once you found the missing file, then you can follow by the first solution by linking the missing file from existing location (e.g. locate crt1.10.6.o). If you will have other missing symbols, then try another file (check the architecture before by: file `locate crt1.10.6.o`).
E.g.
sudo ln -s /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/crt1.10.6.o /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/crt1.10.6.o
sudo ln -s /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/crt1.10.6.o /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/crt1.10.6.o
Related
Error in xcode project: ld: library not found for -lcrt1.10.6.o
If I remember correctly this is what fixed the library not found problem.
CFLAGS="$(OTHER_CFLAGS) -miphoneos-version-min=5.0"
LDFLAGS="$(OTHER_LDFLAGS) --miphoneos-version-min=5.0"
To link this to Xcode, under Build Settings then Header and Library search paths you need to add the paths to the built versions of the library and the header.
You can add the build script as part of your Xcode project, but I haven't had success with this, plus you should only need to build it once per version, so putting the time into anything other than a build script doesn't have much return.
If you decide to put the script in your project anyway (good luck!), then go to the build phases tab, add a build phase of type "Run Script" and paste your script there.