I am trying to integrate some external code into my application. My code was pure C, but the new code is C++, so I simply renamed my C files to .cc and compiled the whole thing with g++.
It compiles fine, but I get a crapton of link errors :
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `operator new(unsigned long, void*)':
svrtH_generator.cc:(.text+0x0): multiple definition of `operator new(unsigned long, void*)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x0): first defined here
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `operator new[](unsigned long, void*)':
svrtH_generator.cc:(.text+0x10): multiple definition of `operator new[](unsigned long, void*)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x10): first defined here
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `operator delete(void*, void*)':
svrtH_generator.cc:(.text+0x20): multiple definition of `operator delete(void*, void*)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x20): first defined here
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `operator delete[](void*, void*)':
svrtH_generator.cc:(.text+0x30): multiple definition of `operator delete[](void*, void*)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x30): first defined here
[you got the idea...]
svrtH_generator.cc:(.text+0x1060): multiple definition of `std::fixed(std::ios_base&)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0xe80): first defined here
collect2: ld returned 1 exit status
make[3]: *** [dev/svrt/libsvrt.so] Error 1
make[2]: *** [dev/svrt/CMakeFiles/svrt.dir/all] Error 2
make[1]: *** [dev/svrt/CMakeFiles/svrt.dir/rule] Error 2
make: *** [svrt] Error 2
I'm using Cmake to build the thing, but nothing really complicated. I don't know why I get all these errors, as my code is just a bunch of methods (I don't use anything from the std package) and the code I try to integrate is not much more complicated.
Note that the warning comes from linking my own code, and not (yet) from the new C++ code.
Anybody ?
EDIT: after digging in the external code I try to integrate, I found some includes :
#include <iostream>
#include <cmath>
#include <fstream>
#include <cfloat>
#include <stdlib.h>
#include <string.h>
Also, iostream is included in other headers, too, and all of them have include guards.
UPDATE: I managed to clean a bit the external code and remove the unnecessary dependencies. I still have some linker errors, but much less :
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `std::abs(long)':
svrtH_generator.cc:(.text+0x0): multiple definition of `std::abs(long)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x0): first defined here
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `__gnu_cxx::abs(long long)':
svrtH_generator.cc:(.text+0x20): multiple definition of `__gnu_cxx::abs(long long)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x20): first defined here
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `__gnu_cxx::div(long long, long long)':
svrtH_generator.cc:(.text+0x40): multiple definition of `__gnu_cxx::div(long long, long long)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x40): first defined here
CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `std::div(long, long)':
svrtH_generator.cc:(.text+0x350): multiple definition of `std::div(long, long)'
CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x150): first defined here
The code includes both cmath
and cstdlib
, and refers to abs and other functions using a default namespace. May this be the problem ?