Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: tron on October 27, 2018, 04:44:00 pm
-
Using Codeblocks 17.12 on Windows 10
Trying to port an old Borland C project, I've changed the c unit files and tested them individually and they work OK, but I'm having problems when I try and put together a project.
I've created a Console application, selecting c as the language then I've added the source files making sure they are included in the active project, the build log suggests they are being compiled but it fails to compile with a undefined reference to 'function' error even though the c source files are there and have relevant the headers included.
I'm stumped at present and I can't work out why it's not working.
Any pointers?
Build Log
-------------- Clean: Debug in ConFuncTest (compiler: GNU GCC Compiler)---------------
Cleaned "ConFuncTest - Debug"
-------------- Build: Debug in ConFuncTest (compiler: GNU GCC Compiler)---------------
mingw32-gcc.exe -Wall -Wwrite-strings -g -IC:\CProjects\Headers -IC:\CProjects\ConFuncTest\ -I"C:\Program Files\CodeBlocks\MinGW\bin" -c C:\CProjects\CIdx\CIdx\libCidx.C -o obj\Debug\CIdx\CIdx\libCidx.o
mingw32-gcc.exe -Wall -Wwrite-strings -g -IC:\CProjects\Headers -IC:\CProjects\ConFuncTest\ -I"C:\Program Files\CodeBlocks\MinGW\bin" -c C:\CProjects\ConFuncTest\confunc.c -o obj\Debug\ConFuncTest\confunc.o
mingw32-gcc.exe -Wall -Wwrite-strings -g -IC:\CProjects\Headers -IC:\CProjects\ConFuncTest\ -I"C:\Program Files\CodeBlocks\MinGW\bin" -c C:\CProjects\ConFuncTest\main.c -o obj\Debug\ConFuncTest\main.o
mingw32-g++.exe -o bin\Debug\ConFuncTest.exe obj\Debug\CIdx\CIdx\libCidx.o obj\Debug\ConFuncTest\confunc.o obj\Debug\ConFuncTest\main.o
obj\Debug\ConFuncTest\main.o: In function `main':
C:/CProjects/ConFuncTest/main.c:25: undefined reference to `idx_open'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
2 error(s), 0 warning(s) (0 minute(s), 3 second(s))
-
Set the priority to main to be higher; would be my guess at a fix.
I am guessing an link order issue.
Right click on file in Management pane, Project Tab
Choose property
Build Tab
Lower the value of priority weight
Tim S.
-
Your mixing the compiling and linking part of the build process.
This is a linking error and means that non of the c files contained a definition of idx_open.
You have to find out why this function hasn't been compiled.
@stahta: Priority won't help here.
-
I've fixed it.
Using the nm utility I found the function names were being mangled as I'm using c not c++ I added
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __cplusplus
extern "C"
}
#endif
Around the code now it compiles and runs.
I presume though I've not looked yet that there must be a way of forcing the compiler to compile as c and not c++
-
This probably happens because .C is regarded as c++ file (if I remember correctly).
Rename it to .c (lower case) and you probably won't need to add the externs...
And check the documentation for your compiler about what is the meaning of different file extensions.