library not found when compiling with gcc on MacOS El capitan - c

I have this problem when compiling with GCC on MacOSX El Capitan. I've already reinstall the Homebrew and GCC but I still can't compile even the simplest program. I have got no idea what is really happening in here:
Koplo$ gcc test.c -o test
ld: library not found for -lgcc
collect2: error: ld returned 1 exit status

I was able to solve the same problem with the following code.
Add this to the Library Search Paths in Build Settings and make sure you select recursive, delete other library paths which might be absolute paths.
$(PROJECT_DIR)
May be it will help you.

Related

undefined reference to gzdopen, gzclose, gzread

I have compiled and installed the 2.2.7.2 version of libxml. While compiling, I have this error: Makefile:755: recipe for target 'install-data-local' failed. But the lib files are correctly generated (libxml2.a and libxml2.so).
I'd like to use libxml2 in a C project so I edited my makefiles in order to integrate lib files (libxml2.a and libxml2.so).
The problem is that when I compile my project I get the followings errors:
/libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzdopen'
/libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzclose'
/libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzread'
...etc
It seems that I have to install the zlib library in order to resolve this linker errors. I installed the zlib library and edited the LD_LIBRARY_PATH in order to add the path where are the zlib libraries.
I recompiled my project, but I still always having the same linker errors.
Would you please help me to resolve those linker errors.
Regards.
See the libxml2 FAQ:
Troubles compiling or linking programs using libxml2
Usually the problem comes from the fact that the compiler doesn't get the right compilation or linking flags. There is a small shell script xml2-config which is installed as part of libxml2 usual install process which provides those flags. Use
xml2-config --cflags
to get the compilation flags and
xml2-config --libs
to get the linker flags. Usually this is done directly from the Makefile as:
CFLAGS=`xml2-config --cflags`
LIBS=`xml2-config --libs`
On my current system, the output from xml2-config --libs is
-lxml2 -lz -lpthread -licucore -lm

CBLAS mac OS X Undefined symbols for architecture x86_64 error

I'm trying different C linear algebra libraries for my projects and now I want to learn BLAS (CBLAS). I am trying to follow the tutorial here. I realised that cblas is already built in the xcode and by adding the flag
gcc foo.c -framework Accelerate
or
gcc foo.c -lcblas
I can remove most of the errors I had before. however there is a final error which I can not find anywhere on the internet.
Undefined symbols for architecture x86_64:
"_printVector", referenced from:
_main in blas1C-63e43d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm not sure where I'm making the mistake but there are a number of possibilities:
I need to instal BLAS/CBLAS from the netlib website. I actually tried to do this but I could manage to build the library from the source code! it would be great if somebody could make a Homebrew formula. then if the original CBLAS library installed then I need to learn about the gcc flags for compiling and how to link the libraries.
or there are syntax differences between the original CBLAS from netlib and the one built in the xcode and I need to change the code.
thanks for your help in advance.
P.S. I'm trying to compile the codes blas1C.c, blaio.c, blaio.h from the page I mentioned.
edit 1: oh my! I just realised that I have made a horrible mistake. the printVector function missing is not part of CBLAS but a function made by the author of the blog. the only thing I had to do was just to compile the blaio.c file as well. so the correct gcc command should be
gcc blas1C.c blaio.c -lcblas
or
gcc blac1C.c blaio.c -framework Accelerate
That function comes from the blasio.c in the website and declared in blasio.h
You need to build blasio and link to it

Gcc collect2: fatal error: cannot find 'ld'

I'm going through the tutorial on making an OS on http://wiki.osdev.org/Bare_Bones. When I try to link boot.o and kernel.o using this command: i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc , I just get this error:
collect2: fatal error: cannot find 'ld'
compilation terminated.
I just installed fresh Ubuntu 15.10 that with gcc-5.2.1 and binutils-2.25.1 .
I have searched the internet for answers but nothing helped.
I also got once the same error during a pentest while I was trying to compile my exploit on the victim server.
In my case, the directory where the "ld" program was located had not been defined in the PATH environment variable, so I simply added it.
eg. export PATH=$PATH:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
I had this error while hacking a remote machine and trying to use gcc to compile an exploit on the victim machine.
I simply copied the program ld to /tmp/, the working directory where i was compiling my exploit exploit.c by running
cp /usr/bin/ld /tmp/ld
followed by the original gcc compile command and the compile worked.
I searched a lot to fix this issue and nothing worked but lastly i uninstalled MinGw and reinstalled it then did edited the environment variables again and then uninstalled and reinstalled vs code extensions then it worked.

ld: library not found for -lplot

I am new here. I recently installed plotutils-dev on my mac using fink, but when I try to compile a little program I have by doing
gcc -g -o atomos.o atomos.c -lplot
it says
ld: library not found for -lplot
collect2: ld returned 1 exit status
I have searched the problem on the web with little success. The only thing I know is that when I type
dpkg -S libplot.dylib
it says
plotutils-dev: /sw/lib/libplot.dylib
which I believe it means I have installed libplot on my mac. So I don't know what is the problem. Any help is welcomed. I am a beginner so It would be nice if some guidelines are provided in a user-friendly way.
The linker can't find the libplot library. I'm not familiar with mac, but with gcc you can tell it the path to the library with the -L flag, e.g.:
gcc -g -o atomos.o atomos.c -lplot -L/sw/lib/
(I'm guessing at that path, but you can probably figure out the path to the library if that isn't right.)
Also, it's probably a typo in your question, but I changed it to -lplot (note extra -l). You want the -l to link with the plot library.

Reason and solution for error -"/usr/bin/ld: cannot find -levent "?

While compiling my program which is using libevent library I am using gcc option -levent. But I am getting this error -
/usr/bin/ld: cannot find -levent
I do not have libevent on my system so I am statically linking to it while compiling using
gcc -o Hello -static -I libevent-1.4.12-stable/ hello.c -levent
How can i resolve this?
Thanks in advance!
Where is the libevent.(a|so) file on your system?
If it isn't on your system's library path then you will have to add a -L option adding its location to the list of paths searched by the linker for libraries.
e.g.
gcc -L/folder/containing/event/lib -levent mysource.cc
You need to have the libevent on your system or need to specify its path explicitly (if its a third-party library you got with the headers).
I suspect its not in your default /lib paths.

Resources