Bug in nvcc 4.0 command-line parameter parser mixing source and object files can break nvcc 4.0

I know that everyone either compiles everything in 2 well separated stages (sources->objects->executables) or sometimes in 1 stage (nvcc *.cu *.cpp )

but what if someone mixed the stages and wrote nvcc a.cu b.o, i.e invoked nvcc on both objects and sources?

It turns out that the result depends on the order the parameters are supplied to nvcc.

If you first feed it with *.cu, and then with *.o, nvcc will treat *.o files as SOURCE files and produce hundreds of meaningless error messages.

If you first feed it with an object file, then with sources, the compilation will proceed smoothly

Here’s an example

Assume we’ve got three files: test.h test.cu main.cu:

// test.h

#pragma once

void foo();
// test.cu

#include "test.h"

#include <iostream>

void foo()

{

 	std::cout << "foo!\n";

}
// main.cu

#include "test.h"

int main()

{

 foo();

}

Now, let’s make a test.o file

> nvcc -c test.cu -o test.o

And compile the program “objects-first” way i.e.

> nvcc test.o main.cu && ./a.out 

foo!

The program compiles and runs!

Now let’s change the order of the arguments to nvcc, i.e. let’s compile the program “sources first” way:

> nvcc main.cu test.o >& error.log

The error.log file contains 624 lines with warnings and errors and looks like this:

test.o:1:8: warning: null character(s) ignored

test.o:1:18: warning: null character(s) ignored

[...]

test.o:76:129: warning: null character(s) ignored

test.o(1): error: unrecognized token

test.o(1): error: expected a declaration

[...]

Error limit reached.

100 errors detected in the compilation of "/tmp/tmpxft_00002ec6_00000000-17_test.cpp1.ii".

Compilation terminated.

As far as I know, this is an nvcc regression:

nvcc 3.2 did not have this problem

(this bug was noticed by my friend when he switched to cuda 4.0 and his project stopped compiling).

Certainly it is an nvcc error to try and compile object files as source files.

Since you already have a repro case in hand, could you [or your friend] please file a bug against the compiler, attaching the repro code and noting the difference in behavior between the CUDA 3.2 and CUDA 4.0 toolchain? Thank you for your help.

That’s what I did yesterday, right after writing a post in this forum, but I still did not get a confirmation e-mail from nvinfo and I cannot find the bug status in nvdeveloper.nvidia.com // Current bugs // search form.

Should I wait?

Hi,

I am getting the same error with cuda 4.0 and please let me know if there is a work around!

Thanks.