News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Cygwin GCC-4 linker options -> Progect buld options?

Started by DBS, November 20, 2010, 04:29:30 AM

Previous topic - Next topic

DBS

I am new in code::blocks, and I am stuck with this problem.

I can compile and build my code with a command-line call to cygwin gcc-4, both from within cygwin and from Windows (7, professional, 64 bit) cmd.  Code::blocks IDE can compile the code, but I have no luck with linking. I can link the object files and produce an executable with this command line:

c:\cygwin\bin\gcc-4 -Wall -Wwrite-strings -Wno-strict-aliasing -g3  -o ex1 ex1.o  -Wl,-rpath,/home/PETScSource/petsc-3.1-p5/cygwin7/lib -L/home/PETScSource/petsc-3.1-p5/cygwin7/lib  -lpetsc  -lf2clapack -lf2cblas -lX11

but I cannot link from the IDE.

I specify the libraries explicitly in Project build options -> linker settings.  No luck.

What do I do wrong?

Thanks.

stahta01

#1
Turn on full Compiler Logging and compare what Code::blocks does to what is needed.

http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

What version of Code::Blocks?
What version of Windows?

Note: Cygwin is not always working very well under Code::Blocks.

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

DBS

Tim,

Thank you for your suggestions.
I use Code::blocks 10.05 Rev 6283
The system is Windows 7 Professional 64 bit installed on Dell Precision Laptop
The cygwin is version 1.7

I have compiled other projects with cygwin GNU compiler no problem. 
I think that the problem is with the option -Wl,-rpath,/home/PETScSource/petsc-3.1-p5/cygwin7/lib
When building through code::blocks, the messages are about unresolved references in the libraries.

I cannot find how to make Code::blocks to call the linker correctly.  Linking via command line works Ok, with the same .o file.

DBS


xunxun

C::B on windows cannot recognize Linux style path. You should replace the path with windows style path.
Regards,
xunxun

DBS

xunxun,

Parameters are passed to the compiler, so unix-style path should be used. 
Nevertheless, I have tried windows path: does not help.

The linker works through Project->Options->makefile, but Buid->clean does not

Should there be a way to pass the same parameters via build options.

xunxun

Quote from: DBS on November 20, 2010, 09:47:07 AM
xunxun,

Parameters are passed to the compiler, so unix-style path should be used. 
Nevertheless, I have tried windows path: does not help.

The linker works through Project->Options->makefile, but Buid->clean does not

Should there be a way to pass the same parameters via build options.

Yea, I know your meaning, but C::B can't know the unix-style path, and the cygwin compiler can recognize the unix-path only when you are in the cygwin bash.
So if you are out of the cygwin bash, you can only use windows path.
Regards,
xunxun

xunxun

#6
Quote from: DBS on November 20, 2010, 09:47:07 AM
xunxun,

Parameters are passed to the compiler, so unix-style path should be used.  
Nevertheless, I have tried windows path: does not help.

The linker works through Project->Options->makefile, but Buid->clean does not

Should there be a way to pass the same parameters via build options.

Did you replace the windows style path "\" with "/"? The cygwin compiler only recognize "/".
For example, "e:\test" should be "e:/test".
Regards,
xunxun

DBS

Finally, I have found a solution.  Tim's suggestion to try full compiler logging turned out to be very helpful.

In Settings->Global Compiler Settings -> Select: cygwin gcc, other settings -> Advanced Options
-> Command Tab: Link object files to console executable (I need a command-line program)
I changed the order in the linker command line template from the default:

$linker $libdirs -o $exe_output $link_objects $link_resobjects $link_options $libs

to

$linker $link_options -o $exe_output $link_objects $link_resobjects $libdirs $libs

Then I just cheated Code::Blocks by putting one of the link directories equal to this option:
-Wl,-rpath,/home/PETScSource/petsc-3.1-p5/cygwin7/lib 

As a result, the IDE compiled a linker command line that works.  Done!