Author Topic: Cygwin GCC-4 linker options -> Progect buld options?  (Read 8101 times)

Offline DBS

  • Single posting newcomer
  • *
  • Posts: 5
Cygwin GCC-4 linker options -> Progect buld options?
« on: November 20, 2010, 04:29:30 am »
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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Cygwin GCC-4 linker options -> Progect buld options?
« Reply #1 on: November 20, 2010, 04:35:12 am »
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.
« Last Edit: November 20, 2010, 04:41:39 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline DBS

  • Single posting newcomer
  • *
  • Posts: 5
Re: Cygwin GCC-4 linker options -> Progect buld options?
« Reply #2 on: November 20, 2010, 07:33:26 am »
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


Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: Cygwin GCC-4 linker options -> Progect buld options?
« Reply #3 on: November 20, 2010, 08:59:04 am »
C::B on windows cannot recognize Linux style path. You should replace the path with windows style path.
Regards,
xunxun

Offline DBS

  • Single posting newcomer
  • *
  • Posts: 5
Re: Cygwin GCC-4 linker options -> Progect buld options?
« Reply #4 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.

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: Cygwin GCC-4 linker options -> Progect buld options?
« Reply #5 on: November 20, 2010, 10:16:29 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

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: Cygwin GCC-4 linker options -> Progect buld options?
« Reply #6 on: November 20, 2010, 10:18:36 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".
« Last Edit: November 20, 2010, 10:20:56 am by xunxun1982 »
Regards,
xunxun

Offline DBS

  • Single posting newcomer
  • *
  • Posts: 5
Re: Cygwin GCC-4 linker options -> Progect buld options?
« Reply #7 on: November 21, 2010, 05:14:51 am »
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!