einpoklum
einpoklum

Reputation: 132086

Link with a boost library fails when compiling with CUDA nvcc, succeeds with gcc

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:

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:

Upvotes: 0

Views: 600

Answers (1)

talonmies
talonmies

Reputation: 72342

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

Upvotes: 1

Related Questions