Author Topic: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.  (Read 4032 times)

Offline BDick

  • Single posting newcomer
  • *
  • Posts: 7
I want to make a static library for windows with the PGI compiler. Compiling and linking of executables with pgfortran works fine, but the built of the library fails. In "settings" the toolchain is set so that "C-compiler", "C++ compiler", and "linker for dynamic libs" all point to pgfortran.exe, and "linker for static libs" points to the lib.exe from Microsoft.

The correct call should be: lib.exe name.o
and generates name.lib

I test this in a command shell.
However, C::B issues the command: lib.exe -r name.a name.o ranlib name.a

How can I tell C::B to omit "-r name.a" and "ranlib name.a"? In the varous dialog boxes I can ADD more options, but I can apparently not REMOVE those superfluous ones.

best regards,
Bernhard

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #1 on: February 13, 2019, 11:20:16 pm »
Copy a compiler then edit the advanced compiler options.

This is what Command: Link Object files to static library shows for "PGI Fortran Compiler"
Code
$lib_linker -r $static_output $link_objects
ranlib $exe_output

Tab: Other Settings Button: Advanced Options
« Last Edit: February 14, 2019, 05:17:46 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 BDick

  • Single posting newcomer
  • *
  • Posts: 7
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #2 on: February 14, 2019, 10:17:27 am »
Thank you very much, with your help I could solve the problem (so I think). In case somebody has a similar problem, here is what I did:

There are two versions of the file "options_pgifortran.xml" on the computer:
one here:           C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\compilers
the second here: C:\Users\dib05004\AppData\Roaming\CodeBlocks\share\codeblocks\compilers

only changes to the second (after making a backup copy) seems necessary.
I changed:

  <Program name="LIB" value="C:\Program Files\PGICE\win64\18.4\bin\ar.exe"/>
  <Switch name="libExtension" value="a"/>
  <Command name="LinkStatic" value="$lib_linker -r $static_output $link_objects&#xA;&#x9;ranlib $exe_output"/>

into:

  <Program name="LIB" value="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\lib.exe"/>
  <Switch name="libExtension" value="lib"/>
  <Command name="LinkStatic" value="$lib_linker  $link_objects $libs /OUT:$exe_output"/>

The first change points to the library manager of Microsoft for x64 host and x64 code. The third invoces this with the correct option for setting the output file name. I found the second change necessary, since otherwise the library gets the extension "a", regardless of what one sets in the "Project Properties -> target" dialog.

Hence, many thanks!
« Last Edit: February 14, 2019, 10:31:40 am by BDick »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #3 on: February 14, 2019, 11:39:40 am »
Thank you for the information, but direct editing of the XML files is not a good idea; Using the Global Compiler Settings is a lot easier and less prone to errors.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #4 on: February 15, 2019, 06:39:07 pm »
If the default settings are wrong you should provide a patch, so it would work fine by default.

@darmar: Do you know if this is something we need to fix?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #5 on: February 15, 2019, 06:58:29 pm »
I am downloading pgi-community-windows-x64 of the compiler; I will see if it installs.
Be about 6 hours just to do the download of the 1 1/2 gig installer.

I think this is the second person with this issue; that I have replied to the post.
But, it was a long time ago with the last one. Did not see a free download on the last one.

Edit: I am still several hours from finishing download; I had to restart from the beginning.
Edit2: Installer refused to install; likely a corrupted download.
Edit3: I have gotten a good download of PGI; but, need to install Win10 SDK and MSVS before PGI will install.
Edit3b: https://www.pgroup.com/support/windows-coinstall.htm

Tim S.
« Last Edit: February 22, 2019, 02:40:28 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 stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #6 on: February 22, 2019, 10:12:42 pm »
I am now working on figuring out how to use the FORTRAN library that I am creating.
Sorry, it took so long; but, my internet is very slow to download 3GB of installers.

Edit: The problem looks hard for a FORTRAN newbie to figure out.
Two clear paths use static linker of "link.exe" or use "pgfortran.exe" to call the linker.
I already decided that using "lib.exe" was not correct.
Edit2: Found a third option using "ar" command.

Tim S.
« Last Edit: February 22, 2019, 10:56:21 pm 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 stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #7 on: February 22, 2019, 11:23:34 pm »
The problem does not seem to be in CB setting to do the static linking; but, I do think adding option "v" for verbose will be very helpful.

The real problem seems to be a PATH issue to find Microsoft's linker command of "link.exe"; my computer was finding the wrong "link.exe" and others might have the same issue.

Tim S.
« Last Edit: February 22, 2019, 11:25:08 pm 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 stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #8 on: February 22, 2019, 11:32:34 pm »
Patch to enable verbose output; that should show the wrong path or missing path to Microsoft link.exe command. Tim S.

Edit: ranlib is just a dummy program for this compiler; so, it can removed.

Code
From ba3dcbab18fdaf062452488ca4b5abfefb964833 Mon Sep 17 00:00:00 2001
From: Tim S <stahta01@gmail.com>
Date: Fri, 22 Feb 2019 17:29:19 -0500
Subject: compiler: Add verbose to PGI static link command. Thanks stahta01

---
 .../compilergcc/resources/compilers/options_pgifortran.xml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml b/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml
index 6e428398b..5ad554875 100644
--- a/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml
+++ b/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml
@@ -202,7 +202,7 @@
     <Command name="LinkDynamic"
              value="$linker -shared $libdirs $link_objects $link_resobjects -o $exe_output $link_options $libs"/>
     <Command name="LinkStatic"
-             value="$lib_linker -r $static_output $link_objects&#38;#xA;&#38;#x9;ranlib $exe_output"/>
+             value="$lib_linker -vr $static_output $link_objects&#38;#xA;&#38;#x9;ranlib $exe_output"/>
     <Command name="LinkNative"
              value="$linker $libdirs -o $exe_output $link_objects $link_resobjects $link_options $libs"/>
 
--
2.19.1.windows.1
« Last Edit: February 23, 2019, 06:53:45 pm 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 BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #9 on: February 24, 2019, 08:39:20 pm »
I am not sure if i can follow?
The conclusion?:
1) Codeblocks does nothing wrong (but it could be improved see 4) )
2) There are two programs called link.exe, and if the path is wrong pgfortran will call the wrong program (can we do something against this?)
3) You can you detect pgfortran is using the wrong path?
4) Is the output of the command if we add this verbose flag cluttered a lot? Can it be added in the normal compiler options, or has it to be added in the "extended" options?

thank you for testing!

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #10 on: February 24, 2019, 10:39:51 pm »
I am not sure if i can follow?
The conclusion?:
1) Codeblocks does nothing wrong (but it could be improved see 4) )
Yes, that was my conclusion; the root cause is the PGI Compiler has missing path to find the linker used by its ar.exe wrapper program.

2) There are two programs called link.exe, and if the path is wrong pgfortran will call the wrong program (can we do something against this?)
Yes, we could auto detect the correct MS Visual Studio link.exe location and add it to the compiler aux. paths

3) You can you detect pgfortran is using the wrong path?
No, the verbose option list the paths that the PGI compiler tried to use.

4) Is the output of the command if we add this verbose flag cluttered a lot? Can it be added in the normal compiler options, or has it to be added in the "extended" options?
We can remove all the advanced fixed options instead of adding it to the advanced options; this might be best.
Edit: This would allow the user to choose to use PGI ar.exe wrapper, MS link.exe, or MS lib.exe.
« Last Edit: February 24, 2019, 10:42:49 pm 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 stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C::B adds options to lib.exe (-r ; ranlib ) that i can not remove.
« Reply #11 on: February 27, 2019, 05:39:48 am »
Edit3: https://sourceforge.net/p/codeblocks/tickets/803/

I figure out a better patch for the OP issue; this allows the OP fix/change to be easier. And, maintains the default way on Linux and Windows. Edit2: It adds the -v for verbose option to the static link command instead of advanced options on Windows.

Tim S.

Code
From 8170d22e6ca089e67d25bb56a08ae1ad615e42e2 Mon Sep 17 00:00:00 2001
From: Tim S <tim.stahlhut@gmail.com>
Date: Tue, 26 Feb 2019 22:08:24 -0500
Subject: [PATCH] - compiler: In win32, move ar options to command (Thanks
 stahta01)

And, removed ranlib command
---
 .../resources/compilers/options_pgifortran.xml       | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml b/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml
index 6e428398b..02a755fc2 100644
--- a/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml
+++ b/src/plugins/compilergcc/resources/compilers/options_pgifortran.xml
@@ -5,7 +5,7 @@
         <Program name="C"       value="pgfortran.exe"/>
         <Program name="CPP"     value="pgfortran.exe"/>
         <Program name="LD"      value="pgfortran.exe"/>
-        <Program name="LIB"     value="ar.exe"/>
+        <Program name="LIB"     value="ar.exe -vr"/>
         <Program name="WINDRES" value=""/>
         <Program name="MAKE"    value="make.exe"/>
     </if>
@@ -201,8 +201,14 @@
              value="$linker $libdirs -o $exe_output $link_objects $link_resobjects $link_options $libs"/>
     <Command name="LinkDynamic"
              value="$linker -shared $libdirs $link_objects $link_resobjects -o $exe_output $link_options $libs"/>
-    <Command name="LinkStatic"
-             value="$lib_linker -r $static_output $link_objects&#xA;&#x9;ranlib $exe_output"/>
+    <if platform="windows">
+      <Command name="LinkStatic"
+               value="$lib_linker $static_output $link_objects"/>
+    </if>
+    <else>
+      <Command name="LinkStatic"
+               value="$lib_linker -r $static_output $link_objects&#xA;&#x9;ranlib $exe_output"/>
+    </else>
     <Command name="LinkNative"
              value="$linker $libdirs -o $exe_output $link_objects $link_resobjects $link_options $libs"/>
 
--
2.21.0.windows.1
« Last Edit: February 27, 2019, 03:04:22 pm 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