I am trying to build a sample code using Eclipse and ARM Sourcery Windows GCC C on Windows 8 machine.
When I compile code :
I get this error :
Undefined reference to symbol 'sem_post##GLIBC_2.4
The error doesn't say any line number or any location about the error, so I don't know which part of the code I should post.
How can I get rid of this error?
Thanks.
sem_post() lives in the pthread library, so make sure you use the -pthread flag when compiling and linking.
gcc <filename.c> - o -lpthread -lrt
Specifying the -lpthread flag, when compiling solved the issue for me
Related
Recently I built a microshell program on Linux. I wanted to work on my MacBookPro (Big Sur 11.6.2) and found out that I'm having issue to compile my program because of the function rl_replace_line of the readline library.
I compile with :
clang -Wall -Wextra -Werror -I./includes
The error I'm having is :
error: implicit declaration of function 'rl_replace_line' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
I found another question on stackoverflow and the answer was to compile with :
-L .brew/opt/readline/lib and -I .brew/opt/readline/include
It doesn't work for me and I'm still having the same error. I tried what brew suggest which is to do :
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
I also tried to compile with -lreadline and it doesn't work.
It still doesn't work for me.
Any idea what I could try to solve this issue ?
Thank you !
I'm trying to compile C with gcc in command prompt but I'm getting this undefined reference to `wWinMain' error.
I was getting undefined reference to `WinMain' first but I fixed that by adding the argument:
-municode
Now `wWinMain' is undefined. How to fix this?
C:\Development\WA\Library\Backend\C\CB\CB>gcc CB.c -lssl -lcrypto -municode
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_w.o):crt0_w.c:(.text+0x21): undefined reference to `wWinMain'
collect2.exe: error: ld returned 1 exit status
gcc CB.c -lssl -lcrypto will compile and link an application, which on Windows defaults to a windowed application for which the entry point is WinMain (which your library obviously does not have nor need).
Adding the -municode just instructs the system to use the windows unicode API and then the entry point becomes wWinMain, and you still have the same problem.
To build a DLL, add -shared: gcc CB.c -shared -lssl -lcrypto
You didn't provide any of your code. And the problem I encountered is similar to this, so I'll describe the experience I had.
I was try out Dear ImGui library, and when I added the -municode option, the linker complained the same thing as yours. I did some searching, and found an answer to a similar question and another comment discussing a related problem, they both suggesting change "main" to "wmain". I did that, and the build was able to succeed.
I'm not knowledgeable enough to provide any deeper information about the source of the problem though.
I am trying to build an example program which uses WinPcap-functions. I’m working under Windows 7 64 Bit edition with MinGW. I am able to compile the C-code to an object file, but I can’t link against wpcap.lib.
My linker call looks like this:
gcc -L ../../lib/x64 send_packet.o -lwpcap -o WinPcapTest.exe
With this call I get the following errors:
undefined reference to pcap_open
undefined reference to pcap_sendpacket
undefined reference to pcap_geterr
Obviously I am not linking against wpcap.lib, but I don’t know why. The library is definitely found. If I change the lib include path for example, I get this error:
cannot find -lwpcap
Why does the linker find the lib but does not link against it? Thanks for your help.
Try listing you libraries after binary definition. As far as I remember, with provided gcc command, ld would be symbol matching for pcap symbols between send_packet.o and libwpcap.lib but not with WinPcapTest.exe. I would suggest moving -lwpcap at the end:
gcc -I ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Include ..\send_packet.c -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 -O0 -g3 -Wall -o WinPcapTest.exe -lwpcap
I am working on a project written in a mix of Fortran 90 and Fortran 77 and now need to link the LAPACK/BLAS libraries, from netlib.org, to the project, all in a Linux environment. I used the gfortran compiler flags OPTS = -O2 -fPIC -m64 in the given Makefile, and then made it using
make blaslib
make
And it finished normally, or at least I think so.
Then, I copied the files in /usr/local/lib and /usr/local/bin/ and /usr/local/lib64/
but it didn't work. I even used the option -L/path/to/lapack/liblapack.a and it didn't work also.
When I compile my code, I get the following error:
qrB.o: In function `qrfactorizeb_':
qrB.f90:(.text+0x64f): undefined reference to `zgeqp3_'
collect2: ld returned 1 exit status
make: *** [run] Error 1
I am really unsure what to make of this error. I tested it in 3 other workstations and it didn't help! Can anyone help me?
I had the same problem some time ago! Dual working with Windows and Linux and also ease of playing with options in Windows taught me something interesting!
Try compiling such as:
[...]$
ifort liblapack.a libblas.a libslatec.a *.o -o profmm
and as you know, it means that I want to use 3 libraries to compile and link my files into profmm output file. It has no syntax error, but it leads to a lot of errors like:
preconditioner3.o: In function factorb_':
preconditioner3.f:(.text+0x1add): undefined reference tozgetrf_'
.
.
preconditioner.o: In function factorpre_':
preconditioner.f:(.text+0x13a2): undefined reference tozgetrf_'
preconditioner.f:(.text+0x18bb): undefined reference to zgetri_'
zbesh.o: In functionzbesh_':
zbesh.f:(.text+0xb3): undefined reference to d1mach_'
zbesh.f:(.text+0xcf): undefined reference toi1mach_'
.
.
.
and many more errors indicating that ifort is unable to read my libraries even though they are here in my current directory!
But simply change the command as follow:
[...]$ ifort *.o liblapack.a libblas.a libslatec.a -o profmm
and it works fine with no error! So it means that now ifort can read my library (local ones)! Also note that changing the order of libraries are very important, and it depends on the order of usage of those subroutines inside the program. So always try to reorder the library chain to check for possible errors.
Hope it helps.
I'm working on a library that must compile on linux and mac os X. Until now, I had no problem, compiling with "-g" worked well under both OS.
I tried to compile with some optimization ("-O2") and it works well under linux but I get an Undefined Symbol when I try to link a program with my library under mac os X.
Does anyone have any clue what I should look for?
nm mylib.a | grep _the_symbol
This returns same thing for linux and mac (no leading underscore under linux) :
154:00000018 C _the_symbol
377: U _the_symbol
Here is the compile line under linux for the program using the library:
/usr/bin/gcc -std=c99 CMakeFiles/prod-cons.dir/prod-cons.c.o -o prod-cons -rdynamic -L/home/claferri/dev/build/src ../src/libckaapi.a -lpthread -Wl,-rpath,/home/claferri/dev/build/src
And under mac :
/usr/bin/gcc -std=c99 -Wl,-search_paths_first -headerpad_max_install_names -fPIC CMakeFiles/prod-cons.dir/prod-cons.c.o -o prod-cons -L/Volumes/Data/claferri/Work/build/src ../src/libckaapi.a /usr/lib/libpthread.dylib
Here's a guess at a workaround: try building the library with the -fno-common flag. If you have multiple definitions of this variable, you'll need to add "extern" to all but one.
Note that the following is a guess, and I can't say for certain unless/until you provide the exact compiler flags you're using -- but Xcode defaults to setting -fvisibility=hidden, which would hide pretty much any symbol in your library, unless it's declared as visible.
You can do the same on Linux, but GCC's default is not to hide symbols.
You'll find more information here: http://gcc.gnu.org/wiki/Visibility