I've faced some strange error with gcc and undefined reference error. I've create simple test project which I compile with gcc:
main.cpp
#include "func.h"
int main(int argc, char *argv[])
{
func();
}
func.h
void func();
func.c
void func()
{
}
The project itself build using QtCreator
so all Makefiles
etc were build automatically. The build commands are:
g++ -o debug\main.o main.cpp
gcc -o debug\func.o func.c
g++ -o debug\app.exe debug/main.o debug/func.o
after that I get error:
main.cpp:9: undefined reference to `func()'
Ok, after lots of attempts I noticed that *.c
file has compiled with gcc
and *.cpp
with g++
. But does it mean? Is *.obj
files formats are different? The problem was solved by changing extension from *.c
to *.cpp
but this still interesting what happened here.