Does linking switch order matters? - gcc

I tried to put up an example using c++ for accessing Cassandra, and so Using Thrift.
Copying the example, I had this strange situation:
storm#debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c prova.cpp -o prova.o
storm#debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c cassandra_constants.cpp -o cassandra_constants.o
storm#debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c cassandra_types.cpp -o cassandra_types.o
storm#debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c Cassandra.cpp -o Cassandra.o
g++storm#debian:~/Script/goh-server/src/cassandra$ g++ -lthrift *.o -o prova
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_login()':
Cassandra.cpp:(.text+0x12d2c): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_set_keyspace()':
Cassandra.cpp:(.text+0x1339c): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_get(org::apache::cassandra::ColumnOrSuperColumn&)':
Cassandra.cpp:(.text+0x13a0b): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_get_slice(std::vector<org::apache::cassandra::ColumnOrSuperColumn, std::allocator<org::apache::cassandra::ColumnOrSuperColumn> >&)':
Cassandra.cpp:(.text+0x142db): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_get_count()':
Cassandra.cpp:(.text+0x14b40): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o:Cassandra.cpp:(.text+0x153bd): more undefined references to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)' follow
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process(boost::shared_ptr<apache::thrift::protocol::TProtocol>, boost::shared_ptr<apache::thrift::protocol::TProtocol>, void*)':
Cassandra.cpp:(.text+0x21511): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_fn(apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int, void*)':
Cassandra.cpp:(.text+0x21882): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_login(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)':
Cassandra.cpp:(.text+0x21fa8): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_set_keyspace(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)':
Cassandra.cpp:(.text+0x2291e): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_get(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)':
Cassandra.cpp:(.text+0x233b9): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o:Cassandra.cpp:(.text+0x23e16): more undefined references to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const' follow
prova.o: In function `main':
prova.cpp:(.text+0x6e): undefined reference to `apache::thrift::transport::TSocket::TSocket(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
prova.o: In function `apache::thrift::transport::TFramedTransport::TFramedTransport(boost::shared_ptr<apache::thrift::transport::TTransport>)':
prova.cpp:(.text._ZN6apache6thrift9transport16TFramedTransportC1EN5boost10shared_ptrINS1_10TTransportEEE[apache::thrift::transport::TFramedTransport::TFramedTransport(boost::shared_ptr<apache::thrift::transport::TTransport>)]+0x26): undefined reference to `vtable for apache::thrift::transport::TFramedTransport'
collect2: ld returned 1 exit status
storm#debian:~/Script/goh-server/src/cassandra$ ls
cassandra_constants.cpp cassandra_constants.o Cassandra.h cassandra_types.cpp cassandra_types.o prova.o
cassandra_constants.h Cassandra.cpp Cassandra.o cassandra_types.h prova.cpp
Then, with some Voodoo I tried to move the -l switch at the end of the linking order, and magically ...
storm#debian:~/Script/goh-server/src/cassandra$ g++ *.o -o prova -lthrift
storm#debian:~/Script/goh-server/src/cassandra$
On the Thrift documentation, the -l switch is put in the beginning, and in fact automake DOES put it before the '*.o's and -o switch.
What's wrong with it ?
Edit:
In fact is not true that automake put -l flags in the beginning. It does put them in the end in the linking stage. Still: why does the order matter ?

It matters. -llibrary must follow everything that references the library.
If you have circular references between static libraries, you end up with -llibrary twice.

Related

libmysqlclient compile error: In function `yaSSLv3_server_method'

I want to compile C files in ubuntu16.04, the makefile file is as follows:
TARGET := matchengine.exe
INCS = -I ../network -I ../utils
LIBS = -L ../utils -lutils -L ../network -lnetwork -Wl,-Bstatic -lev -ljansson -lmpdec -lmysqlclient -lz -lrdkafka -lssl -lcrypto -lhiredis -Wl,-Bdynamic -lm -lpthread -ldl
include ../makefile.inc
I have installed libmysqlclient-dev and mysql-client library using following command:
apt install mysql-client-5.6
apt-get install libmysqlclient-dev
While I compiled the C files , the following errors show:
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(my_default.cc.o):(.data.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(ssl.cpp.o): In function `yaSSLv3_server_method':
(.text+0x60): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(ssl.cpp.o): In function `yaSSLv3_server_method':
(.text+0x9e): undefined reference to `operator delete(void*)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(ssl.cpp.o): In function `yaSSLv3_client_method':
(.text+0xe0): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(ssl.cpp.o): In function `yaSSLv3_client_method':
(.text+0x121): undefined reference to `operator delete(void*)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(ssl.cpp.o): In function `yaTLSv1_server_method':
(.text+0x173): undefined reference to `operator new(unsigned long)'
.....
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(ripemd.cpp.o):(.data.rel.ro._ZTIN8TaoCrypt9RIPEMD160E[_ZTIN8TaoCrypt9RIPEMD160E]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(dh.cpp.o): In function `TaoCrypt::DH::GeneratePrivate(TaoCrypt::RandomNumberGenerator&, unsigned char*)':
(.text+0x122): undefined reference to `operator delete[](void*)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(dh.cpp.o): In function `TaoCrypt::DH::GeneratePrivate(TaoCrypt::RandomNumberGenerator&, unsigned char*)':
(.text+0x145): undefined reference to `operator delete[](void*)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(dh.cpp.o): In function `TaoCrypt::DH::GeneratePrivate(TaoCrypt::RandomNumberGenerator&, unsigned char*)':
(.text+0x162): undefined reference to `operator delete[](void*)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(dh.cpp.o): In function `TaoCrypt::DH::GeneratePrivate(TaoCrypt::RandomNumberGenerator&, unsigned char*)':
(.text+0x1a0): undefined reference to `operator delete[](void*)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(dh.cpp.o): In function `TaoCrypt::DH::GeneratePublic(unsigned char const*, unsigned char*)':
(.text+0x2b3): undefined reference to `operator delete[](void*)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmysqlclient.a(dh.cpp.o):(.text+0x2d0): more undefined references to `operator delete[](void*)' follow

P3DFFT compilation - "Undefined reference" but libraries are linked

I need help with compilation of P3DFFT. I'm literally lost in the process, because the compiler is complaining about "undefined reference" to lots of symbols, but those symbols are present in the libraries.
My command:
mpicc -g -O2 -I../../include -L/home/martin/fftw3/libs -lfftw3 /home/martin/p3dfft/build/libp3dfft.a driver_rand.c -o driver_rand
Compiler output:
driver_rand.c: In function ‘main’:
driver_rand.c:114:10: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(fp,"%d %d %d %d %d\n",&nx,&ny,&nz,&ndim,&n);
^
driver_rand.c:137:8: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(fp,"%d %d\n",dims,dims+1);
^
/tmp/cc52N8Sc.o: In function `Cp3dfft_setup':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:90: undefined reference to `p3dfft_setup'
/tmp/cc52N8Sc.o: In function `Cp3dfft_get_dims':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/tmp/cc52N8Sc.o: In function `Cp3dfft_clean':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:95: undefined reference to `p3dfft_clean'
/tmp/cc52N8Sc.o: In function `Cget_timers':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:105: undefined reference to `get_timers'
/tmp/cc52N8Sc.o: In function `Cset_timers':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:110: undefined reference to `set_timers'
/tmp/cc52N8Sc.o: In function `Cp3dfft_ftran_r2c':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:117: undefined reference to `p3dfft_ftran_r2c'
/tmp/cc52N8Sc.o: In function `Cp3dfft_btran_c2r':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:130: undefined reference to `p3dfft_btran_c2r'
/tmp/cc52N8Sc.o: In function `main':
/home/martin/p3dfft/sample/C/driver_rand.c:106: undefined reference to `set_timers'
/tmp/cc52N8Sc.o: In function `Cp3dfft_setup':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:90: undefined reference to `p3dfft_setup'
/tmp/cc52N8Sc.o: In function `Cp3dfft_get_dims':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/tmp/cc52N8Sc.o: In function `Cp3dfft_ftran_r2c':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:117: undefined reference to `p3dfft_ftran_r2c'
/tmp/cc52N8Sc.o: In function `Cp3dfft_btran_c2r':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:130: undefined reference to `p3dfft_btran_c2r'
/tmp/cc52N8Sc.o: In function `Cp3dfft_clean':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:95: undefined reference to `p3dfft_clean'
/tmp/cc52N8Sc.o: In function `main':
/home/martin/p3dfft/sample/C/driver_rand.c:258: undefined reference to `get_timers'
collect2: error: ld returned 1 exit status
Undefined symbols ARE present in libp3dfft.a:
nm ../../build/libp3dfft.a --defined-only | grep 'p3dfft_setup'
000000000000d030 T __p3dfft_MOD_p3dfft_setup
0000000000010ed0 T p3dfft_setup
nm ../../build/libp3dfft.a --defined-only | grep 'get_timers'
00000000000052f0 T get_timers
0000000000005230 T __p3dfft_MOD_get_timers
Do you have ANY idea what am I doing wrong?
I'm not familiar with your particular compiler, but I think you may need to correct the order of the source file and the libraries on your command line, i.e.
mpicc -g -O2 -I../../include -L/home/martin/fftw3/libs -lfftw3 /home/martin/p3dfft/build/libp3dfft.a driver_rand.c -o driver_rand
should probably be:
mpicc -g -O2 -I../../include driver_rand.c /home/martin/p3dfft/build/libp3dfft.a -L/home/martin/fftw3/libs -lfftw3 -o driver_rand

Buliding llvm examples, /llvm/lib/Support/Mutex.cpp:53: undefined reference to `pthread_mutexattr_init'

I'm attempting to follow the steps on http://llvm.org/docs/tutorial/LangImpl3.html to build the example.
based on
Building llvm examples
#error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
Why am I getting "undefined reference to `dladdr'" even with -ldl for this simple program?
I've ended up with the command
clang++ -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -std=c++11 -g -O3 toy.cpp `llvm-config --libs core --cppflags --ldflags` -o toy
which is giving
/usr/local/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::MutexImpl(bool)':
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:53: undefined reference to `pthread_mutexattr_init'
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:59: undefined reference to `pthread_mutexattr_settype'
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:67: undefined reference to `pthread_mutexattr_destroy'
/usr/local/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:109: undefined reference to `pthread_mutex_trylock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::RWMutexImpl()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:59: undefined reference to `pthread_rwlock_init'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::~RWMutexImpl()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:72: undefined reference to `pthread_rwlock_destroy'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_acquire()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:82: undefined reference to `pthread_rwlock_rdlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_release()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:92: undefined reference to `pthread_rwlock_unlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_acquire()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:102: undefined reference to `pthread_rwlock_wrlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_release()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:112: undefined reference to `pthread_rwlock_unlock'
/usr/local/lib/libLLVMSupport.a(Signals.o): In function `llvm::sys::PrintStackTrace(_IO_FILE*)':
/home/abdev/llvmHome/llvm/lib/Support/Unix/Signals.inc:278: undefined reference to `dladdr'
/home/abdev/llvmHome/llvm/lib/Support/Unix/Signals.inc:290: undefined reference to `dladdr'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::ThreadLocalImpl()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:56: undefined reference to `pthread_key_create'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::~ThreadLocalImpl()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:63: undefined reference to `pthread_key_delete'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::setInstance(void const*)':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:70: undefined reference to `pthread_setspecific'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::getInstance()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:77: undefined reference to `pthread_getspecific'
/usr/local/lib/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:91: undefined reference to `pthread_attr_setstacksize'
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:96: undefined reference to `pthread_create'
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:100: undefined reference to `pthread_join'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Am I missing a library, or is some of the order incorrect?
I believe you need to link with -lpthread or just -pthread

Makefile for Gtk+ and cuda

I'm trying to develop a packet analyzer with CUDA support for pattern matching. I'm using GTK+ for GUI creation but I am not able to compile the GUI file together with the cuda files. How to write makefile for this case?
The project is having two parts: 1. Analyzer 2. GUI
Analyzer consists of many .c,.h files and one .cu file.
GUI part has only one file gui.c
I have included packet_analyzer.h in gui.c.
I tried the following makefile
all: guitest
guitest: gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gcc -lpcap -lpthread `pkg-config --cflags --libs gtk+-2.0` gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gui.o: gui.c
gcc -lpcap -lpthread -c `pkg-config --cflags --libs gtk+-2.0` gui.c
list.o : list.c
gcc -c list.c
queue.o : queue.c
gcc -c queue.c
Word.o : Word.c Word.h
gcc -c Word.c
dictionary.o : dictionary.c
gcc -c dictionary.c
rule.o : rule.c rule.h
gcc -c rule.c rule.h
packet_capturer.o : packet_capturer.c
gcc -lpcap -lpthread -c packet_capturer.c
aho-corasick.o : aho-corasick.c
gcc -lpcap -lpthread -c aho-corasick.c
aho-corasick_cuda.o : aho-corasick_cuda.cu
nvcc -lpcap -lpthread -c aho-corasick_cuda.cu
packet_analyzer.o : packet_analyzer.c
gcc -lpcap -lpthread -c packet_analyzer.c
clean:
rm -rf *o guitest
i end up with the following errors:
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x37): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x86): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xac): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xd5): undefined reference to `cudaMalloc'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xfb): more undefined references to `cudaMalloc' follow
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x132): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x166): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x19d): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x1d1): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x208): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x23c): more undefined references to `cudaMemcpy' follow
aho-corasick_cuda.o: In function `transfer_packets_from_hosttodevice(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x3b1): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x519): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x52b): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x53d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x56b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x58b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5ab): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o: In function `analyze_packets(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x663): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x683): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x6dd): undefined reference to `cudaConfigureCall'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x777): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x78a): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7d5): undefined reference to `Queue_enqueue(Queue*, void*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7f3): undefined reference to `cudaFree'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x802): undefined reference to `cudaFree'
aho-corasick_cuda.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x824): undefined reference to `__cudaUnregisterFatBinary'
aho-corasick_cuda.o: In function `__device_stub__Z14AC_search_CudaPiS_S_S_S_S_S_S_PhiS_(int*, int*, int*, int*, int*, int*, int*, int*, unsigned char*, int, int*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x85c): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x87f): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8a2): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8c5): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8e8): undefined reference to `cudaSetupArgument'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x90b): more undefined references to `cudaSetupArgument' follow
aho-corasick_cuda.o: In function `__sti____cudaRegisterAll_52_tmpxft_00001608_00000000_4_aho_corasick_cuda_cpp1_ii_9958a654()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xa82): undefined reference to `__cudaRegisterFatBinary'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xae3): undefined reference to `__cudaRegisterFunction'
aho-corasick_cuda.o: In function `cudaError cudaLaunch<char>(char*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to `cudaLaunch'
aho-corasick_cuda.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [guitest] Error 1
You need to link with the CUDA runtime library. Add -lcudart to your link command (and CUDA lib path if necessary).
It's the nvcc -lpcap -lpthread $(ANALYZER) -o packet_analyzer.o line that's failing, right? With the -o option, you're telling it to build a complete executable, not just the object files. It needs a main function to do that, which I presume you don't have in any of the $(ANALYZER) files. Instead, try compiling all the sources with the -c flag (like you've done with gcc for gui.c), and then wrap it all together and link it with the other gcc command.

simple problem with makefile or header files?

i have a program that compiles using the following:
g++ -I ../../include -I . -I ../ -I ../../ -I ../ Entity.cpp Attribute.cpp main.cpp -o main.o
The Attribute.cpp includes its header file, Attribute.h, and Attribute.cpp contains all the implementations of Attribute.h.
The Entity.cpp includes the header files Entity.h and Attribute.h, since Entity.cpp uses the Attribute class.
the main.cpp file includes a header file called XML.h, that just includes both the Attribute and Entity headers.
the problem is i keep getting undefined references to functions used in main.cpp and Entity.cpp.
/tmp/ccxKUUNI.o: In function `Entity::entityString() const':
Entity.cpp:(.text+0x3b0): undefined reference to `Attribute::getValueString() const'
Entity.cpp:(.text+0x3c0): undefined reference to `Attribute::getName() const'
/tmp/ccxKUUNI.o: In function `Entity::findAttributePosition(std::basic_string, std::allocator > const&)':
Entity.cpp:(.text+0xb4e): undefined reference to `Attribute::equals(std::basic_string, std::allocator > const&) const'
/tmp/ccxKUUNI.o: In function `Entity::findAttributePositionConst(std::basic_string, std::allocator > const&) const':
Entity.cpp:(.text+0xc24): undefined reference to `Attribute::equals(std::basic_string, std::allocator > const&) const'
/tmp/ccxKUUNI.o: In function `Entity::getAttributeValueString(std::basic_string, std::allocator > const&) const':
Entity.cpp:(.text+0xe0a): undefined reference to `Attribute::getValueString() const'
/tmp/ccvaLwbi.o: In function `main':
main.cpp:(.text+0x2bc): undefined reference to `Entity::addAttribute(Attribute const&)'
main.cpp:(.text+0x359): undefined reference to `Entity::addAttribute(Attribute const&)'
main.cpp:(.text+0x4bb): undefined reference to `Entity::addAttribute(Attribute const&)'
main.cpp:(.text+0x61d): undefined reference to `Entity::addAttribute(Attribute const&)'
main.cpp:(.text+0x77f): undefined reference to `Entity::addAttribute(Attribute const&)'
/tmp/ccvaLwbi.o:main.cpp:(.text+0x8e1): more undefined references to `Entity::addAttribute(Attribute const&)' follow
/tmp/ccvaLwbi.o: In function `main':
main.cpp:(.text+0xc65): undefined reference to `Entity::addEntity(Entity const&)'
main.cpp:(.text+0xd68): undefined reference to `Entity::addAttribute(Attribute const&)'
main.cpp:(.text+0xea9): undefined reference to `Entity::addEntity(Entity const&)'
main.cpp:(.text+0xee1): undefined reference to `Entity::addEntity(Entity const&)'
main.cpp:(.text+0xf53): undefined reference to `Entity::addEntity(Entity const&)'
I know these functions are defined, because their implementations are written in the corresponding cpp files, ie. Entity.cpp and Attribute.cpp.
Thanks.
Okay, problem solved. my question wasn't descriptive enough to have the problem answered,
I was defining functions as inline in the separate cpp file, which causes the compiler to complain about undefined references. So instead I added the implementations to the header file.
Thanks.

Resources