Reputation: 132086
I'm trying to build an executable from just the following code (say it's in the file kt.cu
):
#include <boost/program_options.hpp>
int main(int argc, char** argv)
{
boost::program_options::options_description options("Options");
return 0;
}
Here are 4 possible ways of building it, all should work and result in a binary with no linker errors:
The relevant compilation and linking commands:
Compile with CUDA nvcc:
nvcc -std=c++11 -c kt.cu
Compile with g++ (forcing it to be compiled as a .cpp file would):
g++ -x c++ -std=c++11 -c kt.cu
Link with CUDA nvcc:
nvcc -o kt -lboost_program_options -lcudart -L/usr/local/cuda/lib64 kt.o
Link with g++:
g++ -o kt -rdynamic -lboost_program_options -lcudart -L/usr/local/cuda/lib64 kt.o
If I compile with g++, linking works regardless of which linker I chose (i.e. options 3 and 4 work). If I compile with nvcc, linking fails, regardless of the linker I chose (i.e. options 1 and 2 fail)
Here's the error message I get:
tmpxft_00003de6_00000000-4_kt.cudafe1.cpp:(.text+0x76): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
collect2: error: ld returned 1 exit status
Why is this failing? And what should I do to fix/work around this?
Notes:
apt-get dist-upgrade
s.Upvotes: 0
Views: 600