Fail to build sqlcipher with mingw - linker

I have problem with linking OpenSSL to SqlCipher, it looks like every thing is set up correctly when compiling a simple OpenSSL demo:
gcc -Wall -o ssl-demo testssl.c -lssl -lcrypto -lwsock32 -lgdi32
But when it comes to sqlcipher I get this message:
configure: Release set to 3.7.17
configure: Version number set to 3007017
checking whether to support threadsafe operation... yes
checking for library containing pthread_create... -lpthread
checking for crypto library to use... openssl
checking for HMAC_Init_ex in -lcrypto... no
configure: error: Library crypto not found. Install openssl!"
Looking in the configure.log:
configure:10593: checking for crypto library to use
configure:10660: result: openssl
configure:10662: checking for HMAC_Init_ex in -lcrypto
configure:10687: gcc -o conftest.exe -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -lgdi32 -lssl -lcrypto conftest.c -lcrypto -lpthread >&5
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa0c): undefined reference to `CreateDCA#16'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa19): undefined reference to `CreateCompatibleDC#4'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa2a): undefined reference to `GetDeviceCaps#8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa3a): undefined reference to `GetDeviceCaps#8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa50): undefined reference to `CreateCompatibleBitmap#12'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa5e): undefined reference to `SelectObject#8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xa70): undefined reference to `GetObjectA#12'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xae1): undefined reference to `BitBlt#36'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xaeb): undefined reference to `GetBitmapBits#12'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb42): undefined reference to `SelectObject#8'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb49): undefined reference to `DeleteObject#4'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb53): undefined reference to `DeleteDC#4'
k:/qt/qt4.8.3/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb5d): undefined reference to `DeleteDC#4'
collect2: ld returned 1 exit status
configure:10687: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "sqlcipher"
| #define PACKAGE_TARNAME "sqlcipher"
| #define PACKAGE_VERSION "3.7.17"
| #define PACKAGE_STRING "sqlcipher 3.7.17"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h. */
| #ifdef __cplusplus
| extern "C"
| #endif
| char HMAC_Init_ex ();
| int
| main ()
| {
| return HMAC_Init_ex ();
| ;
| return 0;
| }
configure:10696: result: no
configure:10706: error: Library crypto not found. Install openssl!"
The command used to compile SqlCipher:
$ ./configure --enable-static=no --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lgdi32 -lssl -lcrypto"
I also tried to change the order of linking but that didn't help.

It appears configure is unable to locate your version of libcrypto. Can you try adjusting the LDFLAGS in configure to include -L/some/path/to/your/library.

configure:10687: gcc -o conftest.exe -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -lgdi32 -lssl -lcrypto conftest.c -lcrypto -lpthread >&5
As you can see -lgdi32 goes before the second -lcrypto and it needs to go after. To force this, you have to add LIBS="-lgdi32" to your configure.
If you want to dig into it, see ./configure line 10668 (version 3.7.17).

Related

"checking whether the C compiler works... no", and "configure: error: C compiler cannot create executables" on MacOS Big Sur

I am trying to install PTAMM on my mac, and I have come across this error when trying to configure libcvd.
"checking for gcc... /usr/bin/gcc-4.2
checking whether the C compiler works... no
configure: error: in /Users/myname/Src/libcvd-20100511': configure: error: C compiler cannot create executables See config.log' for more details.
zsh: no such file or directory: /lib"
I have MacOS Big Sur 11.1, XCode 12.5.1.
I believe I have installed the developer tools, but when I run
"xcode-select --install"
I get the error
"xcode-select: error: command line tools are already installed, use "Software Update" to install updates"
To remedy this I have tried uninstalling and reinstalling XCode developer tools, but that did not fix this error. Any advice?
Here is the config.log from configuration.
configure:2626: checking for gcc
configure:2653: result: /usr/bin/gcc-4.2
configure:2882: checking for C compiler version
configure:2891: /usr/bin/gcc-4.2 --version >&5
./configure: line 2893: /usr/bin/gcc-4.2: No such file or directory
configure:2902: $? = 127
configure:2891: /usr/bin/gcc-4.2 -v >&5
./configure: line 2893: /usr/bin/gcc-4.2: No such file or directory
configure:2902: $? = 127
configure:2891: /usr/bin/gcc-4.2 -V >&5
./configure: line 2893: /usr/bin/gcc-4.2: No such file or directory
configure:2902: $? = 127
configure:2891: /usr/bin/gcc-4.2 -qversion >&5
./configure: line 2893: /usr/bin/gcc-4.2: No such file or directory
configure:2902: $? = 127
configure:2922: checking whether the C compiler works
configure:2944: /usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -m32 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -m32 -arch i386 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -m32 conftest.c >&5
./configure: line 2946: /usr/bin/gcc-4.2: No such file or directory
configure:2948: $? = 127
configure:2986: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "CVD"
| #define PACKAGE_TARNAME "cvd"
| #define PACKAGE_VERSION "0.8"
| #define PACKAGE_STRING "CVD 0.8"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:2991: error: in `/Users/zacharywalker-liang/Src/libcvd-20100511':
configure:2995: error: C compiler cannot create executables
See `config.log' for more details.

C header found but function is still undefined

I am on Debian 10 and I want to develop an C application for PostgreSQL. This is why I installed a packages postgresql and libpq-dev. Later clearly installed header files inside the system folders:
┌───┐
│ $ │ ziga > ziga--workstation > 001--hello_world
└─┬─┘
└─> find /usr/include/ | grep libpq
/usr/include/postgresql/libpq-fe.h
/usr/include/postgresql/libpq
/usr/include/postgresql/libpq/libpq-fs.h
/usr/include/postgresql/libpq-events.h
/usr/include/postgresql/internal/libpq
/usr/include/postgresql/internal/libpq/pqcomm.h
/usr/include/postgresql/internal/libpq-int.h
But when I compile this simple C program:
#include <stdio.h>
#include <postgresql/libpq-fe.h>
int main(int argc, char * argv[]){
int v = PQlibVersion();
printf("Version of libpq: %d\n", v);
return 0;
}
compiler says:
gcc -std=c17 -Wall -Wpedantic -g -gdwarf-2 -o main.elf main.c
/usr/bin/ld: /tmp/ccVzig6T.o: in function `main':
/home/ziga/Dropbox/workspace/racunalnistvo/projects--pistam/2021-03-03--postgressql_c/001--hello_world/main.c:6: undefined reference to `PQlibVersion'
collect2: error: ld returned 1 exit status
make: *** [makefile:59: main.elf] Error 1
I don't understand. Header files are inside /usr/include where they should be found...
Is library not being found or what? It is also installed...
┌───┐
│ $ │ ziga > ziga--workstation > 001--hello_world
└─┬─┘
└─> find /usr/lib | grep libpq
/usr/lib/x86_64-linux-gnu/libpq.a
/usr/lib/x86_64-linux-gnu/libpq.so
/usr/lib/x86_64-linux-gnu/libpq.so.5
/usr/lib/x86_64-linux-gnu/pkgconfig/libpq.pc
/usr/lib/x86_64-linux-gnu/libpq.so.5.11
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/pqsignal.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/be-secure-openssl.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/auth.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/pqcomm.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/be-fsstubs.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/pqformat.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/ifaddr.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/be-secure.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/pqmq.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/crypt.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/be-secure-common.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/hba.bc
/usr/lib/postgresql/11/lib/bitcode/postgres/libpq/auth-scram.bc
/usr/lib/postgresql/11/lib/libpqwalreceiver.so
Can anyone tell me how to best solve this?
As the log says, The linker is unable to find any reference to PQlibVersion. Since the linker is running, it clearly is not a problem of compiling but linking.
/usr/bin/ld: /tmp/ccVzig6T.o: in function `main':
/home/ziga/Dropbox/workspace/racunalnistvo/projects--pistam/2021-03-03--postgressql_c/001--hello_world/main.c:6: undefined reference to `PQlibVersion'
collect2: error: ld returned 1 exit status
I think you should add linker options to link against the postgress library. Add -lpq option to you compiler arguments. For a more complete explanation, please read Building libpq Programs.

crosscompile libcurl for arm on freeRtos and LWIP

I'm trying to cross-compile libcurl from a linux ubuntu x86_64 system.
My target is an embedded platform based on an arm crotex-m4 NXP micro, flash ram and flash memory are not a concern.
AFAIK libcurl does not require a OS to run over but just wanted a UNIX like flavaour TCP_IP stack. To complain with this point I use a port of LWIP tcp-ip stack for my architecture.
In addition I've already built a library (.a) out from FreeRtos + LWIP + drivers and named it libProject_prova1.a (you will find it in the directives)
Then I wrote a shell script to perform the configure step of the make build that shows as follows:
#! /bin/sh
export PATH=/usr/local/mcuxpressoide-10.0.2_411/ide/tools/bin:$PATH
PATH=/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/Release:$PATH
export ROOTDIR="${PWD}"
export MBEDDIR=/home/user/Desktop/mbed_TLS_NXP/build
export PROJDIR=/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1
cd ./curl-7.55.0
export CPPFLAGS="-DUSE_LWIPSOCK -D__REDLIB__ -DLWIP_DNS=1 -DUSE_RTOS=1 -DCR_INTEGER_PRINTF -DSDK_DEBUGCONSOLE=0 -D__MCUXPRESSO -D__USE_CMSIS -DNDEBUG -DFSL_RTOS_FREE_RTOS -DSDK_OS_FREE_RTOS -DCPU_LPC54608J512ET180 -DCPU_LPC54608J512ET180_cm4 -I${PROJDIR}/lwip/src/include/lwip -I${PROJDIR}/lwip/src/include/lwip/priv -I${PROJDIR}/lwip/src/include/lwip/prot -I${PROJDIR}/lwip/src/include/netif -I${PROJDIR}/lwip/src/include/netif/ppp -I${PROJDIR}/lwip/src/include/netif/ppp/polarssl -I${PROJDIR}/lwip/src/include/posix -I${PROJDIR}/lwip/src/include/posix/sys -I${PROJDIR}/lwip/port -I${PROJDIR}/lwip/port/arch -I${PROJDIR}/lwip/src -I${PROJDIR}/lwip/src/include -I${PROJDIR}/lwip/src/netif -I${PROJDIR} -I${PROJDIR}/drivers -I${PROJDIR}/utilities -I${PROJDIR}/freertos -I${PROJDIR}/CMSIS -I${PROJDIR}/startup -I${MBEDDIR}/include/mbedtls"
export CFLAGS="-O0 -fno-common -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -specs=redlib.specs"
export LDFLAGS="-L${MBEDDIR}/lib -L${PROJDIR}/Release"
export LIBS="-lProject_prova1"
export CROSS_COMPILE=arm-none-eabi
export AR=${CROSS_COMPILE}-ar
export AS=${CROSS_COMPILE}-as
export LD=${CROSS_COMPILE}-ld
export RANLIB=${CROSS_COMPILE}-ranlib
export CC=${CROSS_COMPILE}-gcc
export NM=${CROSS_COMPILE}-nm
export PREFIX=${ROOTDIR}/build
./configure --target=${CROSS_COMPILE} --host=${CROSS_COMPILE} --prefix=${ROOTDIR}/build --build=x86_64-linux-gnu --without-ssl --with-mbedtls --enable-static --disable-shared --disable-ftp --disable-file --disable-pop3 --disable-smb --disable-smtp --disable-imap --disable-ldap --disable-ldaps --disable-dict --disable-telnet --disable-tftp --disable-manual --disable-ipv6 --disable-unix-sockets --disable-versioned-symbols --disable-ares --disable-sspi --disable-gopher --without-zlib --without-libssh2 --without-ca-bundle -without-ca-path --without-libidn --without-librtmp --without-libidn
Unfortunatly what I obtain is:
checking for grep... /bin/grep
checking for egrep... /bin/grep -E
checking for a BSD-compatible install... /usr/bin/install -c
checking for arm-none-eabi-gcc... arm-none-eabi-gcc
checking whether the C compiler works... no
configure: error: in `/home/user/Desktop/curl_libProject_prova1/curl-7.55.0':
configure: error: C compiler cannot create executables
See `config.log' for more details
In the log file I cannot find an explanation:
configure:4781: checking whether the C compiler works
configure:4803: arm-none-eabi-gcc -O0 -fno-common -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb --specs=redlib.specs -D__REDLIB__ -DUSE_LWIPSOCK -DLWIP_DNS=1 -DUSE_RTOS=1 -DCR_INTEGER_PRINTF -DSDK_DEBUGCONSOLE=0 -D__MCUXPRESSO -D__USE_CMSIS -DNDEBUG -DFSL_RTOS_FREE_RTOS -DSDK_OS_FREE_RTOS -DCPU_LPC54608J512ET180 -DCPU_LPC54608J512ET180_cm4 -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/lwip -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/lwip/priv -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/lwip/prot -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/netif -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/netif/ppp -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/netif/ppp/polarssl -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/posix -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include/posix/sys -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/port -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/port/arch -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/include -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/lwip/src/netif -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1 -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/drivers -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/utilities -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/freertos -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/CMSIS -I/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/startup -I/home/user/Desktop/mbed_TLS_NXP/build/include/mbedtls -L/home/user/Desktop/mbed_TLS_NXP/build/lib -L/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/Release conftest.c -lProject_prova1 >&5
configure:4807: $? = 0
configure:4845: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "curl"
| #define PACKAGE_TARNAME "curl"
| #define PACKAGE_VERSION "-"
| #define PACKAGE_STRING "curl -"
| #define PACKAGE_BUGREPORT "a suitable curl mailing list: https://curl.haxx.se/mail/"
| #define PACKAGE_URL ""
| /* end confdefs.h. */
|
| int main (void)
| {
|
| ;
| return 0;
| }
configure:4850: error: in `/home/user/Desktop/curl_libProject_prova1/curl-7.55.0':
configure:4852: error: C compiler cannot create executables
See `config.log' for more details
I'm not understanding where the problem is.
redlib.spec is a nxp custom C library, see:
https://community.nxp.com/thread/389152
It's important to use redlib otherwise I will have conflicts with what is defined in LWIP and arm-gnu-none-eabi standard C lib (e.g. redefinition of structure or typedef).
I've tried a simple dumb compilation an linkage to see if I was messing up something in the cpplfags, libs and so on...and noticed that it works.
For this example I did the following:
C source:
#include "lwip/netdb.h"
int main(){
char* name="www.google.it";
gethostbyname(name);
return 0;
}
compiler directives:
export PATH=/usr/local/mcuxpressoide-10.0.2_411/ide/tools/bin:$PATH
PATH=/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1/Release:$PATH
export PROJDIR=/home/user/Documents/MCUXpresso_10.0.2_411/workspace/libProject_prova1
export CPPFLAGS="-DUSE_LWIPSOCK -D__REDLIB__ -DLWIP_DNS=1 -DUSE_RTOS=1 -DCR_INTEGER_PRINTF -DSDK_DEBUGCONSOLE=0 -D__MCUXPRESSO -D__USE_CMSIS -DNDEBUG -DFSL_RTOS_FREE_RTOS -DSDK_OS_FREE_RTOS -DCPU_LPC54608J512ET180 -DCPU_LPC54608J512ET180_cm4 -I${PROJDIR}/lwip/src/include/lwip -I${PROJDIR}/lwip/src/include/lwip/priv -I${PROJDIR}/lwip/src/include/lwip/prot -I${PROJDIR}/lwip/src/include/netif -I${PROJDIR}/lwip/src/include/netif/ppp -I${PROJDIR}/lwip/src/include/netif/ppp/polarssl -I${PROJDIR}/lwip/src/include/posix -I${PROJDIR}/lwip/src/include/posix/sys -I${PROJDIR}/lwip/port -I${PROJDIR}/lwip/port/arch -I${PROJDIR}/lwip/src -I${PROJDIR}/lwip/src/include -I${PROJDIR}/lwip/src/netif -I${PROJDIR} -I${PROJDIR}/drivers -I${PROJDIR}/utilities -I${PROJDIR}/freertos -I${PROJDIR}/CMSIS -I${PROJDIR}/startup"
arm-none-eabi-gcc -O0 -fno-common -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -D__REDLIB__ -specs=redlib.specs main.c ${CPPFLAGS} -L${PROJDIR}/Release -lProject_prova1 -o main
I will kindly appreciate any help you may give me.

How do I link Intel MKL and libdl with gold linker?

I'm having a problem linking Intel MKL and libdl using the gold linker on CentOS:
When I run this script:
#!/bin/bash
MKL_INC=$MKL_INSTALL_DIR/include
MKL_LIB=$MKL_INSTALL_DIR/lib
. /opt/rh/devtoolset-6/enable
cat > t.c << end_mkltest
#include <dlfcn.h>
#include "mkl_service.h"
int main() {
dlerror(); /* use libdl */
mkl_set_num_threads(1); /* use mkl */
}
end_mkltest
gcc -I$MKL_INC -c t.c -o t.o
gcc -L$MKL_LIB -fuse-ld=gold t.o -lmkl_rt -ldl
I get:
libmkl_rt.so: error: undefined reference to 'calloc'
libmkl_rt.so: error: undefined reference to 'realloc'
libmkl_rt.so: error: undefined reference to 'malloc'
libmkl_rt.so: error: undefined reference to 'free'
We're using:
CentOS 7.3
devtoolset-6
mkl-2017.2.174.tar.bz2
Any ideas?
This should work. Can you post the linker command shown by this command?
gcc -v -L$MKL_LIB -fuse-ld=gold t.o -lmkl_rt -ldl
(Sorry, can't post this as a comment due to lack of reputation.)

undefined reference when compiling code with cfitsio library [duplicate]

This question already has answers here:
Undefined reference to 'pthread_create' — linker command option order (libraries before/after object files?) [duplicate]
(2 answers)
Closed 6 years ago.
I am receiving an undefined reference error for every function used from the cfitsio library when compiling my code. Below is the relevant chunk of the make null command's output (Note that -L/usr/lib/ -lcfitsio is in the first line):
gcc -g -I../mdl/null -DCHABRIER -DCHANGESOFT -DDENSITYU -DDENSITYUNOTP -DDIFFUSION -DDODVDS -DDTADJUST -DEPSACCH -DPARTICLESPLIT -DPROMOTE -DGASOLINE -DJEANSSOFT -DNSMOOTHINNER -DRTFORCE -DSETTRAPFPE -DSTARFORM -DTHERMALCOND -DTOPHATFEEDBACK -DTWOPHASE -DVSIGVISC -DWENDLAND -DRADIATION -DRADIATIONLUM -DDDSIMPLE -DR2PPBMAX -DCOOLING_METAL -L/usr/lib/ -lcfitsio -I/usr/include/fitsio.h -o gasoline.dfTest main.o master.o param.o outtype.o pkd.o pst.o grav.o ewald.o walk.o eccanom.o hypanom.o fdl.o htable.o smooth.o smoothfcn.o collision.o qqsmooth.o cooling_metal.o cosmo.o romberg.o starform.o feedback.o millerscalo.o supernova.o supernovaia.o startime.o stiff.o runge.o dumpframe.o dffuncs.o dumpvoxel.o rotbar.o special.o ssio.o treezip.o log.o radiation.o erf.o v_sqrt1.o ../mdl/null/mdl.o -lm
dumpframe.o: In function `fitsError':
/.../dumpframe.c:2156: undefined reference to `ffrprt'
dumpframe.o: In function `dfFinishFrame':
/.../dumpframe.c:2175: undefined reference to `ffinit'
/.../dumpframe.c:2176: undefined reference to `ffcrim'
/.../dumpframe.c:2197: undefined reference to `ffppr'
/.../dumpframe.c:2198: undefined reference to `ffclos'
collect2: error: ld returned 1 exit status
Makefile:539: recipe for target 'gasoline.dfTest' failed
make[1]: *** [gasoline.dfTest] Error 1
make[1]: Leaving directory '/home/grondjj/Code/gasoline'
Makefile:457: recipe for target 'null' failed
make: *** [null] Error 2gcc -g -I../mdl/null -DCHABRIER -DCHANGESOFT -DDENSITYU -DDENSITYUNOTP -DDIFFUSION -DDODVDS -DDTADJUST -DEPSACCH -DPARTICLESPLIT -DPROMOTE -DGASOLINE -DJEANSSOFT -DNSMOOTHINNER -DRTFORCE -DSETTRAPFPE -DSTARFORM -DTHERMALCOND -DTOPHATFEEDBACK -DTWOPHASE -DVSIGVISC -DWENDLAND -DRADIATION -DRADIATIONLUM -DDDSIMPLE -DR2PPBMAX -DCOOLING_METAL -L/usr/lib/ -lcfitsio -I/usr/include/fitsio.h -o gasoline.dfTest main.o master.o param.o outtype.o pkd.o pst.o grav.o ewald.o walk.o eccanom.o hypanom.o fdl.o htable.o smooth.o smoothfcn.o collision.o qqsmooth.o cooling_metal.o cosmo.o romberg.o starform.o feedback.o millerscalo.o supernova.o supernovaia.o startime.o stiff.o runge.o dumpframe.o dffuncs.o dumpvoxel.o rotbar.o special.o ssio.o treezip.o log.o radiation.o erf.o v_sqrt1.o ../mdl/null/mdl.o -lm
dumpframe.o: In function `fitsError':
/.../dumpframe.c:2156: undefined reference to `ffrprt'
dumpframe.o: In function `dfFinishFrame':
/.../dumpframe.c:2175: undefined reference to `ffinit'
/.../dumpframe.c:2176: undefined reference to `ffcrim'
/.../dumpframe.c:2197: undefined reference to `ffppr'
/.../dumpframe.c:2198: undefined reference to `ffclos'
collect2: error: ld returned 1 exit status
Makefile:539: recipe for target 'gasoline.dfTest' failed
make[1]: *** [gasoline.dfTest] Error 1
make[1]: Leaving directory '/home/grondjj/Code/gasoline'
Makefile:457: recipe for target 'null' failed
make: *** [null] Error 2
Here are the relevant lines from the Makefile for make null
FITS_LIB = -L/usr/lib/ -lcfitsio
BASE_LD_FLAGS = $(PNG_LIB) $(GSL_LIB) $(FITS_LIB)
NULL_LD_FLAGS = $(BASE_LD_FLAGS)
null:
cd $(NULL_MDL); make "CC=$(CC)" "CFLAGS=$(NULL_CFLAGS)"
make $(EXE) "CFLAGS=$(NULL_CFLAGS)" "LD_FLAGS=$(NULL_LD_FLAGS)"\
"MDL=$(NULL_MDL)" "XOBJ=$(NULL_XOBJ)" "LIBMDL=$(NULL_LIBMDL)"
In dumpframe.c I include the cfitsio header fitsio.h along with the other inlcudes at the top of the file:
#ifndef GSS_DUMPFRAME
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include "fitsio.h"
The library was installed from source code. The source resides in /usr/local/src/cfitsio/, it was then installed via the following commands:
$ ./configure --prefix=/usr
$ make shared
$ make install
$ make clean
Which results in the libraries (libcfitsio.a, libcfitsio.so, libcfitsio.so.5, libcfitsio.so.5.3.39) being installed in /usr/lib/ and the auxiliary files (longnam.h, fitsio.h, fitsio2.h, drvrsmem.h) being installed in /usr/include/.
I am not sure what causes this, as the compiler does not complain about missing libraries or a missing fitsio.h header file.
Put the library after the object files, not before.
Wrong:
gcc -g -I../mdl/null -DCHABRIER -DCHANGESOFT -DDENSITYU -DDENSITYUNOTP \
-DDIFFUSION -DDODVDS -DDTADJUST -DEPSACCH -DPARTICLESPLIT -DPROMOTE \
-DGASOLINE -DJEANSSOFT -DNSMOOTHINNER -DRTFORCE -DSETTRAPFPE -DSTARFORM \
-DTHERMALCOND -DTOPHATFEEDBACK -DTWOPHASE -DVSIGVISC -DWENDLAND -DRADIATION \
-DRADIATIONLUM -DDDSIMPLE -DR2PPBMAX -DCOOLING_METAL \
-L/usr/lib/ -lcfitsio -I/usr/include/fitsio.h \
-o gasoline.dfTest main.o master.o param.o outtype.o pkd.o pst.o grav.o ewald.o \
walk.o eccanom.o hypanom.o fdl.o htable.o smooth.o smoothfcn.o collision.o \
qqsmooth.o cooling_metal.o cosmo.o romberg.o starform.o feedback.o millerscalo.o \
supernova.o supernovaia.o startime.o stiff.o runge.o dumpframe.o dffuncs.o \
dumpvoxel.o rotbar.o special.o ssio.o treezip.o log.o radiation.o erf.o v_sqrt1.o \
../mdl/null/mdl.o -lm
Right:
gcc -g -I../mdl/null -DCHABRIER -DCHANGESOFT -DDENSITYU -DDENSITYUNOTP \
-DDIFFUSION -DDODVDS -DDTADJUST -DEPSACCH -DPARTICLESPLIT -DPROMOTE \
-DGASOLINE -DJEANSSOFT -DNSMOOTHINNER -DRTFORCE -DSETTRAPFPE -DSTARFORM \
-DTHERMALCOND -DTOPHATFEEDBACK -DTWOPHASE -DVSIGVISC -DWENDLAND -DRADIATION \
-DRADIATIONLUM -DDDSIMPLE -DR2PPBMAX -DCOOLING_METAL \
-o gasoline.dfTest main.o master.o param.o outtype.o pkd.o pst.o grav.o ewald.o \
walk.o eccanom.o hypanom.o fdl.o htable.o smooth.o smoothfcn.o collision.o \
qqsmooth.o cooling_metal.o cosmo.o romberg.o starform.o feedback.o millerscalo.o \
supernova.o supernovaia.o startime.o stiff.o runge.o dumpframe.o dffuncs.o \
dumpvoxel.o rotbar.o special.o ssio.o treezip.o log.o radiation.o erf.o v_sqrt1.o \
../mdl/null/mdl.o -lcfitsio -lm
Note that the -I/usr/include/cfitsio.h option does no good, though it also does no harm given that the header is in /usr/include. The -I option takes a directory name, not a file name. Similarly, the -L/usr/lib option does no good, though it too does no harm either. The /usr/lib library is searched automatically.

Resources