I have the following setup:
main.c:
extern void sol();
int main(){
sol();
}
sol.cc:
#include<iostream>
using namespace std;
void sol(){
cout<<"HW!!\n";
}
I compile to separate object files:
$gcc main.c -c
$g++ sol.cc -c
But when I try to link them to a single executable,
$g++ main.o sol.o
I get: main.c:(.text+0x7): undefined reference to 'sol'
, nm sol.o
shows that there is 00000000 T _Z3solv
, while nm main.o
requires U sol
. I found out that C++ renames functions to avoid same names of overloaded functions. Is there any way to tell compiler that sol.o
contains renamed functions, or to compile sol.cc
without renaming them?