Author Topic: Compiles twice: C and C++  (Read 6750 times)

Offline New2CB

  • Single posting newcomer
  • *
  • Posts: 2
Compiles twice: C and C++
« on: October 31, 2013, 09:23:52 pm »
I'm trying to use Code Blocks to compile some programs under C instead of C++.  They were written a long time ago and have C specific code.  I set the compile option: -x c so that it will use the gnu c compiler.  I also set the "Save build log to HTML file when build is finished." option so I got results in html format, which explains the html tags in my post.  After doing a clean then a build, I got:

------------------------------------
mingw32-gcc.exe -Wall  -g -x c     -c G:\MYSRC\main.c -o obj\Debug\main.o<br />
G:\MYSRC\main.c: In function 'main':<br />
<font color="#0000ff">G:\MYSRC\main.c:8:5: warning: implicit declaration of function 'xmalloc' [-Wimplicit-function-declaration]</font><br />
<font color="#0000ff">G:\MYSRC\main.c:8:12: warning: assignment makes pointer from integer without a cast [enabled by default]</font><br />
<font color="#0000ff">G:\MYSRC\main.c:6:12: warning: variable 'mylist' set but not used [-Wunused-but-set-variable]</font><br />
mingw32-gcc.exe  -o bin\Debug\simple.exe obj\Debug\main.o    <br />
obj\Debug\main.o: In function `main':<br />
<font color="#ff0000">G:/MYSRC/main.c:8: undefined reference to `xmalloc'</font><br />
collect2.exe: error: ld returned 1 exit status<br />
------------------------------------

I took the advice at the post:
How to compile only in C Mode only. Using GCC compiler
« on: August 08, 2013, 05:45:09 pm »
and changed the Toolchain executables for Linker dynamic libs from mingw32-g++.exe to mingw32-gcc.exe.  That had no effect.
This is weird.  It's running the compile twice.  What could be causing this?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7789
    • My Best Post
Re: Compiles twice: C and C++
« Reply #1 on: October 31, 2013, 09:36:42 pm »
Wrong!

It is Compiling and then Linking.

If you wish it to link with the gcc instead of g++; edit the linker under the compiler toolchain settings.

Edit: added link http://wiki.codeblocks.org/index.php?title=Installing_a_supported_compiler#Compiler-neutral_setup_steps

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

Offline New2CB

  • Single posting newcomer
  • *
  • Posts: 2
Re: Compiles twice: C and C++
« Reply #2 on: October 31, 2013, 10:10:25 pm »
I had already set the linker to gcc instead of g++.  As a test I changed the compiler for C++ from g++ to gcc.  That had no effect, which means that CB wasn't trying to do a C++ compile in the first place, which means the problem was in the link step.  It looks like the gcc linker doesn't know about xmalloc.