Author Topic: No link with libc function  (Read 968 times)

Offline MichelSimian

  • Single posting newcomer
  • *
  • Posts: 4
No link with libc function
« on: September 27, 2018, 02:01:44 pm »
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



Offline MichelSimian

  • Single posting newcomer
  • *
  • Posts: 4
Re: No link with libc function
« Reply #2 on: October 01, 2018, 11:23:51 am »
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 :
-------------------
Code: [Select]
||=== 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 :
------------
Code: [Select]
-------------- 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



Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2492
Re: No link with libc function
« Reply #3 on: October 01, 2018, 11:28:07 am »
please make a rebuild and post the build log:
Build->Clean
Build->Build

or

Build->Rebuild

what is your main signature?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2492
Re: No link with libc function
« Reply #4 on: October 01, 2018, 11:32:30 am »
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
Code: [Select]
mingw32-g++.exe

Offline MichelSimian

  • Single posting newcomer
  • *
  • Posts: 4
Re: No link with libc function
« Reply #5 on: October 01, 2018, 11:33:37 am »
This is the Bluid log after a Build>Clean

Code: [Select]

-------------- 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))
 

Offline MichelSimian

  • Single posting newcomer
  • *
  • Posts: 4
Re: No link with libc function
« Reply #6 on: October 01, 2018, 11:38:51 am »
OK, I change the linker in mingw32-g++ as proposed, and it fixes the problem.

See new build with right linker command :

Code: [Select]

-------------- 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 :)