Author Topic: Error compiling under Cygwin  (Read 5175 times)

Offline JSeb

  • Single posting newcomer
  • *
  • Posts: 3
Error compiling under Cygwin
« on: December 02, 2007, 05:34:58 pm »
Hi gurus, wizards and newbies.

I a new Code::Blocks convert, after flirting a bit with wxDev-CPP, and being dissapointed.

I tried to configure CB for CYGWIN by following the instruction here:
http://wiki.codeblocks.org/index.php?title=Installing_Cygwin_Compiler

I then tried to compile the ubiquitous "Hello World" code, and obtained an avalanche of errors ("was not decalred in this scope"... I don't think the exact errors are relevant in this post).

Looking at the Build Log, the first line reads:
g++.exe -mno-cygwin -IC:/Cygwin/usr/include -c "C:/Documents and Settings/JSeb/Mes documents/WorkSpace/FooBar2/main.cpp" -o obj/Debug/main.o


I then went to my cygwin console, and tried to compile with
g++.exe -mno-cygwin -c main.cpp -o main

Surprise surprise, it worked.

So in CB, Settings->Compiler and Debugger->Global Compiler Settings, tab Search directories->Compiler, I just erased the path C:\Cygwin\usr\include. Now the first line of the Buil Log reads:
g++.exe -mno-cygwin -c "C:/Documents and Settings/JSeb/Mes documents/WorkSpace/FooBar2/main.cpp" -o obj/Debug/main.o

And the compilation is successful.

So, what is happening here? Did I set up CB correctly to be used with Cygwin? How come explicitly specifying the search directory in the first case fails? Will I have any trouble?

Thank you kindly for your help!


Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Error compiling under Cygwin
« Reply #1 on: December 02, 2007, 08:40:30 pm »
I'm not sure, but a rough guess about what the problem might be is this:
1. -mno-cygwin tell the compiler to build a "no cygwin" program (duh).
2. you specify a header search path that contains cygwin standard headers which don't contain something (some CRT funcs)
3. the compiler uses the headers found there and doesn't find some CRT functions it needs.

That's only a guess, not even knowing what the actual errors were. Probably it should compile without that compiler switch (but with the include path), too.

Seeing that you build a MinGW program (using -mno-cygwin), I wonder why you don't use MinGW in the first place. Other than Cygwin, MinGW is officially supported by Code::Blocks.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline JSeb

  • Single posting newcomer
  • *
  • Posts: 3
Re: Error compiling under Cygwin
« Reply #2 on: December 02, 2007, 10:08:00 pm »
Thank you Thomas!

That's only a guess, not even knowing what the actual errors were. Probably it should compile without that compiler switch (but with the include path), too.
Well, you're right. It does compile without the switch (of course, the .exe complains about not finding cygwin1.dll). I don't know why  :(

Seeing that you build a MinGW program (using -mno-cygwin), I wonder why you don't use MinGW in the first place. Other than Cygwin, MinGW is officially supported by Code::Blocks.
I'm using Cygwin because I'm using development libraries I was not able to install under Mingw. That's another story. The point is, CB supports GNU GCC, so it should work with Cygwin.

I would be grateful if anyone could tell how to configure CB to work properly with cygwin.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Error compiling under Cygwin
« Reply #3 on: December 02, 2007, 10:26:38 pm »
Well, either with the include path and without the switch, or without the include path and with the switch :)

Note that compiling without the switch links against the cygwin library which makes your program GPL bound.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline JSeb

  • Single posting newcomer
  • *
  • Posts: 3
Re: Error compiling under Cygwin
« Reply #4 on: December 02, 2007, 11:22:01 pm »
Well, either with the include path and without the switch, or without the include path and with the switch :)
Makes sense :oops:. I'll go with that and hope I won't have any problems later on. You see, I believe YOU understand what's happening here. I sorry to say I don't quite get it. That's the problem when you spend too much time with Visual Studio: you don't quite remember what goes on behind the scene (linking? yeah, I've seen that in my CS class...).

So... maybe I might ask about the other tabs under Settings->Compiler and Debugger->Global Compiler Settings->Search directories? currently, Linker only contains path C:\Cygwin\lib, and Resource compiler contains C:\Cygwin\usr\include (Compiler is now empty). I know I can at least compile my hello world code, but does that setting makes sense for projects that are a little bit more ambitious?

Thank you so much!

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Error compiling under Cygwin
« Reply #5 on: December 03, 2007, 08:58:04 am »
In addition: I believe what happended was the foillowing:
If you want to use the -mno-cygwin switch that this mght mean that you need to install all the MinGG packages in Cygwin, too. I'm not sure if they are installed by default. So propably if you use this switch and don't have them installed the compiler/linker would error correctly. This would also be a reason for why it works without this switch: Because it then uses Cygwin "native" libs and stuff which are istalled by default - so no complaints.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ