Author Topic: Project not Compiling  (Read 2537 times)

Offline tron

  • Single posting newcomer
  • *
  • Posts: 2
Project not Compiling
« 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))

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Project not Compiling
« Reply #1 on: October 27, 2018, 04:59:40 pm »
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.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Project not Compiling
« Reply #2 on: October 27, 2018, 06:13:40 pm »
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline tron

  • Single posting newcomer
  • *
  • Posts: 2
Re: Project not Compiling
« Reply #3 on: October 28, 2018, 12:57:55 pm »
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++

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Project not Compiling
« Reply #4 on: October 28, 2018, 01:01:26 pm »
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]