I want connect to postgresql by libpqxx (C++)
When running g++ with -lpq I got this error:
[michael#michael cpp]$ g++ Store.cpp -lpqxx -std=c++11 -lpq
/usr/bin/ld: cannot find -lpq collect2: error: ld returned 1 exit
status
When I remove -lpq it's run well and work, I want to know why with -lpq it's not work and how fix it.
Thanks, Michael.
Related
I have a c++ program, which uses the FFTW3 library, which I would like to translate to Fortran. I am using Ubuntu 22.04.1.
I installed the FFTW3 library as detailed in Installation on UNIX
The c++ main program is named ksbenchmark.cpp and, using g++, I compile it and link it (to the math and fftw3 libraries) with
g++ -o my_executable.out ksbenchmark.cpp -lm -lfftw3
which works great.
I have translate the c++ code in Fortran, the source file being named ksbenchmrk.f90.
If I issue
gfortran ksbenchmark.f90 -lfftw3 -lm
I get error messages
/usr/bin/ld: /tmp/cca2xMGa.o: in function `ksintegrate_':
ksbenchmark.f90:(.text+0x59): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x94): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksbenchmark.f90:(.text+0xcf): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x4de): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x5db): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x626): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x780): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0xa1c): undefined reference to `dfftw_execute_'
collect2: error: ld returned 1 exit status
I have spent the afternoon reading about it, and it seems I may have to use -I and -L flags such as
gfortran test.f90 -L/new/path/to/lib -I/new/path/to/include -lfftw3 -lm
as illustrated in the post Problems linking FFTW with gfortran (symbol(s) not found for architecture x86_64).
The first question is, what paths to use?
I can find files referring to fftw3 in /usr/local/lib as well as in /usr/local/include, but the attempt
gfortran ksbenchmark.f90 -L/usr/local/lib -I/usr/local/include -lfftw3 -lm
returns the same error as before
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
/usr/bin/ld: /tmp/ccW2DYGP.o: in function `ksintegrate_':
ksintegrate.f90:(.text+0x62): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksintegrate.f90:(.text+0x9d): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksintegrate.f90:(.text+0xd8): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksintegrate.f90:(.text+0x4df): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0x5f7): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0x643): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0x79d): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0xa5b): undefined reference to `dfftw_execute_'
collect2: error: ld returned 1 exit status
I am unable to understand which paths to the library are to be used.
How to find where the library is saved?
Why does not g++ need any paths to the library?
I apologise for how trivial the question might seem, I am a total newbie can ensure I put a significant effort in trying to sort this out. Any hint would be most appreciated, thanks
EDIT
Following Vladimir F Героям слава's advice, I tried using the nm command to verify the library contains what is expected to.
In /usr/local/lib
I found libfftw3.a and libfftw3.la files.
Issuing nm libfftw3.a I get quite a long list.
I tried looking for one of the commands I get an error about, dfftw_plan_dft_1d
nm -S libfftw3.a | grep dfftw_plan_dft_1d
and indeed it returns hits
00000000000003a0 0000000000000026 T _Z18dfftw_plan_dft_1d_PP11fftw_plan_sPiPA2_dS4_S2_S2_
0000000000002df0 0000000000000026 T _Z19dfftw_plan_dft_1d__PP11fftw_plan_sPiPA2_dS4_S2_S2_
I am trying to compile nettle 3.0 with gmp 6.0.0 and I kept getting missing symbols:
Making all in tools
gcc -g -O2 -ggdb3 -Wno-pointer-sign -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wpointer-arith -Wbad-function-cast -Wnested-externs -L.. pkcs1-conv.o misc.o ../getopt.o ../getopt1.o -lhogweed -lnettle -lgmp -o pkcs1-conv
ld: warning: relocation error: R_386_32: file ../getopt.o: symbol optarg: external symbolic relocation against non-allocatable section .debug_info; cannot be processed at runtime: relocation ignored
Undefined first referenced
symbol in file
__gmpz_limbs_write ../libhogweed.so
__gmpz_limbs_finish ../libhogweed.so
__gmpz_limbs_modify ../libhogweed.so
__gmpn_zero ../libhogweed.so
__gmpz_roinit_n ../libhogweed.so
__gmpn_cnd_sub_n ../libhogweed.so
__gmpn_cnd_add_n ../libhogweed.so
__gmpz_limbs_read ../libhogweed.so
ld: fatal: symbol referencing errors
collect2: error: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `pkcs1-conv'
Current working directory /root/nettle-3.0/tools
I installed gmp 6.0.0 to /usr/local, then - in the nettle directory -, I ran ./configure --prefix=/usr/local, then make and got the error above.
It looks nettle is finding an older version first. Have you tried?
./configure --prefix=/usr/local --with-include-path=/usr/local/include --with-lib-path=/usr/local/lib
I found the options by using ./configure --help.
im triying to compile a object from the source
http://xeat-engine.googlecode.com/svn/trunk/
using the code
g++ -c wx-config --cxxflags main.cpp
g++ -o main main.o wx-config --libs
and obtain the error
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function _start':
(.text+0x20): undefined reference tomain'
collect2: error: ld returned 1 exit status
please help me to fix the problem
What could I do?
IS A CAPTURE FOR MAIN.CPP
http://i.stack.imgur.com/TziYb.jpg
You're missing:
wxIMPLEMENT_APP(xeatengine_guiApp);
which will be expanded into a valid main() function.
NOTE: the trailing semicolon is necessary...
See also:
wxDECLARE_APP(xeatengine_guiApp);
I'm trying to build a C static library (.a) that is compatible with a MIPS processor (I'm working in an embedded system).
To do so I tried to execute the following commands (obs: I'm using the mipsel-unknown-elf tool):
mipsel-unknown-elf-gcc -o math.o -c math.c
(No erros followed this command)
mipsel-unknown-elf-gcc -archive -o libmath.a math.o -lm
With this command I got the following error message:
cannot find -lm
collect2: ld returned 1 exit status
By getting this message I tried to add a -L/path argument:
mipsel-unknown-elf-gcc -archive -o libmath.a math.o -L/usr/lib/i386-linux-gnu -lm
But then I got the following error:
skipping incompatible /usr/lib/i386-linux-gnu/libm.a when searching for -lm
cannot find -lm
collect2: ld returned 1 exit status
Does anyone knows what's going on?
Your cross compiler distribution should include a MIPS libm.a. I just checked and I found several libm.a versions in my installation of CodeSourcery mips-linux-gnu-gcc. I don't have mipsel-unknown-elf-gcc installed, so I can't check that. If the mips-linux-gnu- version of libm.a is self contained, you might try using that version.
I'm trying to compile a program provided to me. I noticed in the Makefile it runs the command
g++ -o test [...] -lpthread
I noticed the pthread library file is in /lib/libpthread.so.0 , but when I try to make the target, it gives me this error:
/usr/bin/ld: cannot find -lpthread
collect2: ld returned 1 exit status
how do I fix this?
In order to use -lpthread, you need a libpthread.a library archive and this is for static linking. libpthread.so.0 is a shared object which means it is used for dynamic linking. See GCC Link Options