0

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:

  1. Compile with CUDA nvcc, link with CUDA nvcc
  2. Compile with CUDA nvcc, link with g++
  3. Compile with g++, link with CUDA nvcc
  4. Compile with g++, link with g++

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:

  • I'm using Debian stretch with regular apt-get dist-upgrades.
  • I don't think there's something special about boost::program_options, i.e. it happens with other boost libs when I also use them. It's probably not boost-specific either, although I can't really say.
  • Versions (which shouldn't matter I think): CUDA 7.5, Boost 1.58, g++4.9.3. Also tried g++ 4.8.5 with same effect. Also tried compiling and linmking with g++ 5.2.1 only, that worked as well.
  • Edit: I can confirm this does not occur on Fedora 20, with g++ 4.8.3, Boost 1.54, CUDA 7.5. Can it be something with the Boost version?
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 2
    As near as I can tell, the commands you've shown for building that file using g++ are just duplicated compile commands - I don't see the link step anywhere. In any event, I had no trouble compiling and linking the code with nvcc like [this](http://pastebin.com/Gjvr4ztn), on Fedora 20, boost 1.54, CUDA 7.5, gnu 4.8.3. [This](http://pastebin.com/p4t6sBNS) also worked, compiling with nvcc and linking with g++. – Robert Crovella Nov 25 '15 at 02:26
  • @RobertCrovella: See my edit. – einpoklum Nov 25 '15 at 09:41

1 Answers1

1

This is a boost incompatibility with gcc 5 as a linker. See here. Downgrade to gcc 4 or wait for a patch.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
talonmies
  • 70,661
  • 34
  • 192
  • 269