Linking fftw-3.3.6-pl2 while compiling my file using gcc - c

I'm trying to run a simple code that includes the fftw library. I know the code is right as it is provided as a test code by the authors. This is what I typed during compilation:
gcc my file.c -L/home/ankit/Desktop/fftw-3.3.6-pl2/lib/
-I/home/ankit/Desktop/fftw-3.3.6-pl2/include/ -lfftw -lm
I get the errors:
myfile.c: (.Text+0x2c):. undefined reference to 'fftw_plan_dft_2d'
collect2: ld returned 1 exit status

It wasn't a linking problem, installation was faulty and I had to use 'sudo make install' to get the permission for the installation to be successful. I could link it with 'gcc test.c -lfftw3 -lm' after. Thanks for your suggestions!

Related

(Windows) GCC linker cannot find -lcheck and -lsubunit (But all headers are fine)

I am trying to compile C code that uses check.h with this command on Windows 11:
gcc new_test.c s21_decimal.a -lcheck -lm -lpthread -lsubunit -o new_test
But then i get this error:
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lcheck: No such file or directory
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lsubunit: No such file or directory
collect2: error: ld returned 1 exit status
So, GCC cannot find check and subunit, but it sure finds check.h header and all the other headers.
What is the most common way to fix this?
Can I download check and subunit (are those .lib?) manually and give these to GCC? If I can - how do I do this?
GCC version: gcc (GCC) 11.3.0

DSO missing from command line although it is available

I am working with c++ code for a physics simulation, which uses a lot of external libraries (like GSL and cern`s ROOT). Trying to recompile project I encountered problems with linking. When running compilation of final file via:
g++ -fno-inline -O2 -fpic -o main.out ${ROOTINCS} main.o ext.o ${ROOTLIBS} $(objects2)
with :
objects2= many .o files made by us
ROOTLIBS=-L/usr/local/lib/root -lTree -lRIO -lNet -lHist -lMathCore -lCore -lGraf -lGraf3d -lGpad -lMatrix -lThread -lCint -lPhysics -lPostscript -lRint -lSpectrum -lg
ROOTINCS=-pthread -m64
I get annoying error:
/usr/bin/ld: /usr/local/lib/root/libHist.so: undefined reference to symbol 'gRandom'
/usr/local/lib/root/libMathCore.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
The problem is nm -C run on libMathCore states 'gRandom' is declared there. Also -lMathCore is present in my command line.
When I run ld to check if it understands the flag:
ld -L/usr/local/lib/root -lMathCore --verbose 2>/dev/null
it does not complain and tries to link properly.
According to https://stackoverflow.com/a/24675715/3602168 order of libraries is correct in my linking (libHist uses libMathCOre and therefore is stated first).
Compilation runs under g++ 4.8.2 on ubuntu 14.04, 64 bit
Converting comment to answer:
Have you tried moving $(objects2) before ${ROOTLIBS}? I think the issue may be that you have libraries specified before the object files that use them.

Error occurs when compiling with GCC

I am attempting to compile a C program with multiple files on window platform. However, when I make it, errors are occurred. I have already tried to modify command in makefile but still could not fix it.
This is my GCC command:
gcc -o "SYSMONTR" $(OBJPATH)/chkdsksp ../chkdsksp.c -g -I"$(DB2PATH)/include" -I"$(MYLIBDIR)" $(MYIQDIR)/iqclilib.a $(OBJPATH)/icrou.a -lc -ldb2 -lnsl -L"$(DB2PATH)/lib"
This is result:
gcc -o "SYSMONTR" ../../iLINKOBJ/chkdsksp ../chkdsksp.c -g -I"C:/Program Files/IBM/SQLLIB/include" -I"../../iLINKCLIB" ../../iLINKIQOBJ/iqclilib.a ../../iLINKOBJ/icrou.a -lc -ldb2 -lnsl -L"C:/Program Files/IBM/SQLLIB/lib"
../../iLINKOBJ/chkdsksp: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
makefile:49: recipe for target `SYSMONTR' failed
make: *** [SYSMONTR] Error 1
What could cause such error and what should I do with it? Using cygwin on Window (IDE: Eclipse).
Any supports will be appreciated.
If chkdsksp is an object file built by another team to run on AIX, you cannot expect it to function -- or even be recognized by your compiler -- on Cygwin. You must contact that team and get a) the source code or b) a version of the object file compiled for your platform (and tested).

undefined reference error CUDA, GPUJPEG Library

I have successfully installed this library. My code compiles without issue but I'm getting this error, which I believe is during linking:
suvamsh#vai:~/gpujpeg-lib/src$ nvcc test.cu
/tmp/tmpxft_00002869_00000000-13_test.o: In function 'encoder()':
tmpxft_00002869_00000000-1_test.cudafe1.cpp:(.text+0x23d): undefined reference to `gpujpeg_set_default_parameters(gpujpeg_parameters*)'
collect2: ld returned 1 exit status
I have even set $LD_LIBRARY_PATH to location of the library .so file.
Any help would be greatly appreciated!
As indicated by #talonmies,
You will have to explicitly specify the library to the compiler and supply the path where you installed it, if it is in a "non-standard" place.
Try the following command
$ nvcc test.cu -o test -L"path/to/GPUJPEGLibrary" -l"name_of_GPUJPEGLibrary"
Note that if the name of the .so file is libxyz.so, the "name_of_GPUJPEGLibrary" should be "xyz".
For example, if your .so file is /usr/local/lib/libgpujpeg.so, the cmdline should be
$ nvcc test.cu -o test -L"/usr/local/lib" -l"gpujpeg"

program links properly on school machine, but not on personal one: undefined reference to log

I can ssh to my schools Ubuntu 11.04 server where I have to submit my code and this links fine:
ME#SCHOOL:~/309/project2$ make
gcc -lm treesort.c -o treesort
ME#SCHOOL:~/309/project2$
My local machine is running Ubuntu 12.04 and here is the compiler output for the same code, but using the NetBeans makefile:
gcc -lm -o dist/Release/GNU-Linux-x86/treesort build/Release/GNU-Linux-x86/sortFns.o build/Release/GNU-Linux-x86/treesort.o
build/Release/GNU-Linux-x86/treesort.o: In function `processargs':
treesort.c:(.text+0x144): undefined reference to `log'
collect2: ld returned 1 exit status
Using the command line on my local machine with the same code and makefile from the first example:
ME#MYCOMPUTER:~/Documents/CSCI/309/project2$ make
gcc -lm treesort.c -o treesort
/tmp/ccY5GqF1.o: In function `processargs':
treesort.c:(.text+0x2b5): undefined reference to `log'
collect2: ld returned 1 exit status
make: *** [all] Error 1
ME#MYCOMPUTER:~/Documents/CSCI/309/project2$
This is really quite irritating, and I can't figure out why it works on the server and not on my local machine. I found this question, but it didn't help.
Put -lm at the end of the link line. The order of sources,objects and (archive) libraries on the link line matters, and yours is wrong.
If putting -lm at the end of the link line doesn't help, you have some bogus library called libm.{a,so} somewhere on your system, and you should figure out where it came from, and get rid of it.
You cam find out which libm your linker is finding with gcc -Wl,-t ...

Resources