iAdjunct
iAdjunct

Reputation: 2979

Xilinx sdk: linker won't link cross-c/c++

I'm using the Xilinx SDK to compile for the Zynq 7020.

An example of the problem I'm having is this

SomeFile.c:

void someFunction () { }

SomeFile.h

void someFunction () ;

main.cpp

extern "C" {
#include "SomeFile.h"
}

int main ( int , char const* * ) {
    someFunction () ; // This line
    return 0 ;
}

The line labeled "This line" gets a linker error because it cannot find the symbol "someFunction".

I know the .c file is being compiled (if I put a garbage character in it, it fails to build). I know it has the same prototype (but, with C linkage, that doesn't matter).

It seems the Xilinx suite isn't running the linker between C/C++ object files, and I don't know how to convince it to do so.

How do I fix this?

Note: this is using the gnu toolchain.

Upvotes: 1

Views: 641

Answers (1)

iAdjunct
iAdjunct

Reputation: 2979

So it turns out this is because the Xilinx SDK defaulted to compiling the .c file with g++, not gcc, which emitted the C++-mangled name for someFunction instead of the C name. Then, when the .cpp file used extern "C" to reference it, it was looking for a C-style symbol, not the C++-style [mangled] symbol.

I had to right click on the .c files to get to their build settings and manually change the compiler from whatever-whatever-g++ to whatever-whatever-gcc then it worked.

Upvotes: 1

Related Questions