News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

No link with libc function

Started by MichelSimian, September 27, 2018, 02:01:44 PM

Previous topic - Next topic

MichelSimian

Hi,
I faced a problem with C::B (13.2) for windows. It no more links with standard C functions. Those functions (like printf, ...) are unreferenced. It happened suddenly because one month ago, I was able to compile and link all my projects...

Thus, I uninstalled C::B and installed it from the codeblock-mingw setup for windows (last release from december 17). I created a console application and try to compile it (the default main.c with printf("Hello world")...
It fails, with unreference __main and puts functions. I tried with other projects and noticed that all functions like printf cannot link.

I tried to compile using the same mingw toolchain directly in a bat file. It works...

Usually, C::B links by default without special configuration. What's wrong ?

Thanks



MichelSimian

Hi,

I'm using Code::Block version 17.2 on Windows Seven PRO 64bits service pack 1. Compiler is mingw-gcc (tdm-1) 5.1.0 (supplied by the Codeblock installer)

When I create a console-application project, and compile the default main.c supplied, it fails with unresolved reference to __main and puts.

Build messages :
-------------------

||=== Build: Debug in bidon (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\Win7PRO\Documents\bidon\main.c|5|undefined reference to `__main'|
C:\Users\Win7PRO\Documents\bidon\main.c|6|undefined reference to `puts'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


Build log :
------------

-------------- Build: Debug in bidon (compiler: GNU GCC Compiler)---------------

ld.exe  -o bin\Debug\bidon.exe obj\Debug\main.o   
obj\Debug\main.o: In function `main':
C:/Users/Win7PRO/Documents/bidon/main.c:5: undefined reference to `__main'
C:/Users/Win7PRO/Documents/bidon/main.c:6: undefined reference to `puts'
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))


When I compile it in a command line, it works

I already tried to uninstall Code::Block and to reinstall it. It did not fix the problem.

I tried to build a previous project which has lot of sources and lib to link and it failed with the printf, and other "libc" functions.

What is wrong on the installation ?

Thanks



BlueHazzard

please make a rebuild and post the build log:
Build->Clean
Build->Build

or

Build->Rebuild

what is your main signature?

BlueHazzard

Why do you use ld to link and not g++?
Have you changed the compiler settings?

Check in Settings->Compiler->Toolchain executables->Linker for dynamic libs
There should be
mingw32-g++.exe

MichelSimian

This is the Bluid log after a Build>Clean



-------------- Build: Debug in bidon (compiler: GNU GCC Compiler)---------------

gcc.exe -Wall -g  -c C:\Users\Win7PRO\Documents\bidon\main.c -o obj\Debug\main.o
ld.exe  -o bin\Debug\bidon.exe obj\Debug\main.o   
obj\Debug\main.o: In function `main':
C:/Users/Win7PRO/Documents/bidon/main.c:5: undefined reference to `__main'
C:/Users/Win7PRO/Documents/bidon/main.c:6: undefined reference to `puts'
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))


MichelSimian

OK, I change the linker in mingw32-g++ as proposed, and it fixes the problem.

See new build with right linker command :



-------------- Build: Debug in bidon (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe  -o bin\Debug\bidon.exe obj\Debug\main.o   
Output file is bin\Debug\bidon.exe with size 28.47 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))



Thanks a lot :)