Author Topic: Linking libraries (.lib fortran)  (Read 7884 times)

Offline Librarylinker

  • Single posting newcomer
  • *
  • Posts: 6
Linking libraries (.lib fortran)
« on: February 13, 2020, 12:57:32 am »
Hi,

I am trying to link 3 libraries (.lib) to a project. The libraries are BLASd, LAPACKd, MATGENd (which might be intel libraries as they are in upper case - which I think wouldn't be the source of error)

I am using wingw64 to as fortran compiler.

I didn't install nothing but the IDE and the compiler, i.e., I just have the .lib files and I am trying to link them to the projects...

I did what I think was needed to link the libraries which is:
- settings > compiler > search directories > linker > add: (added the path to the 3 .lib files)
I did the same to compiler (although I think it isn't necessary for fortran) i.e.
- settings > compiler > search directories > compiler> add: (added the path to the 3 .lib files)
Added the libraries to the projects build options:
- project > build options > linker settings > linker libraries > add> (added BLASd, LAPACKd and MATGENd)
(I've  read here and there that the order of this list is important, so I tried all the combinations: BLM, BML, LBM, LMB, MBL, MLB...)

I think everything should work fine, but I end up getting an error message:
undefined reference to `dgemm_'

For simplicity, uploaded a small program example which I have this error (cant attach to the post because to lib files exceed the limit): https://drive.google.com/open?id=1dj9s_KOmC3hVjqBkAO_GArwyqGb6eK-w

This sounds like a horrendously simple question and it might be. But to me, it might end up consuming literally the rest of my life if I can't get any help of someone more experienced to tell me what might be going on here.

If anybody could help with this, you don't know how much you would be changing a man's life

Thanks in advance
« Last Edit: February 13, 2020, 01:17:02 am by Librarylinker »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Linking libraries (.lib fortran)
« Reply #1 on: February 13, 2020, 01:21:57 am »
I don't know anything about fortran, but I'll start from here:
http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Also I'll try to add one library at a time if this is possible. Start from the lower levels and keep adding the upper levels.
And consider asking the help from the place where you've downloaded the libraries. They might know if they are compatible with your compiler and version.
(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 Librarylinker

  • Single posting newcomer
  • *
  • Posts: 6
Re: Linking libraries (.lib fortran)
« Reply #2 on: February 13, 2020, 01:31:06 am »
Thank you for the answer.

[And consider asking the help from the place where you've downloaded the libraries.]
Those are old files, I won't be able to track the origin... but I know in 2012 it was used for windows, MVS IDE, intel compiler and recently it was used for linux, gfortran (which I whink is the same compiler I am using, but mine is windows). So it seems that they should be compatible with mine...

Anyone else that might have a solution for this problem (which doesn't seem to be complex in actaulity), I tried all logical solution I could imagine
« Last Edit: February 13, 2020, 02:52:56 am by Librarylinker »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Linking libraries (.lib fortran)
« Reply #3 on: February 13, 2020, 03:52:49 am »
Post a build log and maybe some could help you!
In case it is a simple mistake; without a build log you are wasting band width and everyone's time

Edit: BLAS and LAPACK are libraries that building them yourself is likely possible.
But,  MATGEN is not a library that Google has very much about.
Edit2: Most of the Google results is about the matgen command/program. I have not found a matgen library!

Tim S.
« Last Edit: February 13, 2020, 04:01:24 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 cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Linking libraries (.lib fortran)
« Reply #4 on: February 13, 2020, 08:44:51 am »
I think everything should work fine, but I end up getting an error message:
undefined reference to `dgemm_'

That looks like a linker error.

I don't know the compiler(s) you are using or whether your project is all Fortran or mixed C++/Fortran, or whether the libraries were compiled by you. A *.lib library is the typical result of Visual Studio-compatible compiler (I guess it is Intel Fortran nowadays, in ancient times it was Fortran Powerstation and before history began it was VAX Fortran). GCC or variants typically create *.a static libraries if I am not mistaken.

So the question is whether your wingw64 compiler produces compatible object code with those intel libraries, probably compiled with an Intel compiler.  From the '_' suffix I am guessing it does not, it is what your wingw64 compiler expects it to be, but the intel compiler probably 'decorates' the subroutine names in a different way, causing the linker error.

Your best bet is to recompile those libraries using the compiler you are using, or alternatively use an intel compiler for your own code.

I used to deal with such issues a long time ago when calling Fortran from C++ http://arnholm.org/software/cppf77/cppf77.htm


Offline Librarylinker

  • Single posting newcomer
  • *
  • Posts: 6
Re: Linking libraries (.lib fortran)
« Reply #5 on: February 13, 2020, 11:26:19 am »
Post a build log and maybe some could help you!
In case it is a simple mistake; without a build log you are wasting band width and everyone's time

Edit: BLAS and LAPACK are libraries that building them yourself is likely possible.
But,  MATGEN is not a library that Google has very much about.
Edit2: Most of the Google results is about the matgen command/program. I have not found a matgen library!

Tim S.
Build log would just say that undefined reference error and I added a short program example too. It is all there, thanks
And just ignore the part I say it is simple, I am more time then you wouldn't believe, trying to fix this. That's why I ened up asking here

 
I think everything should work fine, but I end up getting an error message:
undefined reference to `dgemm_'

That looks like a linker error.

I don't know the compiler(s) you are using or whether your project is all Fortran or mixed C++/Fortran, or whether the libraries were compiled by you. A *.lib library is the typical result of Visual Studio-compatible compiler (I guess it is Intel Fortran nowadays, in ancient times it was Fortran Powerstation and before history began it was VAX Fortran). GCC or variants typically create *.a static libraries if I am not mistaken.

So the question is whether your wingw64 compiler produces compatible object code with those intel libraries, probably compiled with an Intel compiler.  From the '_' suffix I am guessing it does not, it is what your wingw64 compiler expects it to be, but the intel compiler probably 'decorates' the subroutine names in a different way, causing the linker error.

Your best bet is to recompile those libraries using the compiler you are using, or alternatively use an intel compiler for your own code.

I used to deal with such issues a long time ago when calling Fortran from C++ http://arnholm.org/software/cppf77/cppf77.htm


Thank you for the answer.
It is all fortran (like the program example).
The libraires were probably downloaded from intel.
Do you have the source code so I can recompile?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
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: Linking libraries (.lib fortran)
« Reply #7 on: February 13, 2020, 12:39:14 pm »
Sample FORTRAN file builds OK for me; with minor code edit.

The library blas has the dgemm function.
Note: It still built after removing the lapack from linker library list.

Using MSys2 MinGW64 lapack library (which installs blas library)
Code
$ pacman -Qs lapack
local/mingw-w64-x86_64-lapack 3.8.0-5
    Linear Algebra PACKage (mingw-w64)

Tim S.

Code
-------------- Build: Debug in dgemm (compiler: GNU Fortran Compiler)---------------

gfortran.exe -Jobj\Debug\ -Wall  -g     -c C:\Users\stahta01\devel\test\dgemm\main.f95 -o obj\Debug\main.o
gfortran.exe  -o bin\Debug\dgemm.exe obj\Debug\main.o   -llapack -lblas
Output file is bin\Debug\dgemm.exe with size 319.11 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
« Last Edit: February 13, 2020, 12:42:13 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 cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Linking libraries (.lib fortran)
« Reply #8 on: February 13, 2020, 01:02:10 pm »
Do you have the source code so I can recompile?

No.

Offline Librarylinker

  • Single posting newcomer
  • *
  • Posts: 6
Re: Linking libraries (.lib fortran)
« Reply #9 on: February 13, 2020, 03:10:19 pm »
Sample FORTRAN file builds OK for me; with minor code edit.

What did you do?

You just installed the file from http://netlib.org/lapack/lapack.tgz by using MSys2 MinGW64, is that it? (I'm not experienced in dealing with those things, I'm not sure if I understood what you did. I guess you didn't create a .a library and simply linked it. And also you are not working with the .lib I provided, right?)

Would you be able to compile it with Codeblocks IDE?
« Last Edit: February 13, 2020, 03:51:09 pm by Librarylinker »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Linking libraries (.lib fortran)
« Reply #10 on: February 13, 2020, 06:14:43 pm »
Sample FORTRAN file builds OK for me; with minor code edit.

What did you do?

You just installed the file from http://netlib.org/lapack/lapack.tgz by using MSys2 MinGW64, is that it? (I'm not experienced in dealing with those things, I'm not sure if I understood what you did. I guess you didn't create a .a library and simply linked it. And also you are not working with the .lib I provided, right?)

Would you be able to compile it with Codeblocks IDE?

I used the MSys2 Mingw64 64 bit GCC [FORTRAN] compiler!
The Code::Blocks IDE is not an compiler!!!!!!
I used mingw .a libraries.
I used the MSys2 Mingw64 lapack package that installs blas library.

Tim S.
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 Librarylinker

  • Single posting newcomer
  • *
  • Posts: 6
Re: Linking libraries (.lib fortran)
« Reply #11 on: February 13, 2020, 06:44:51 pm »
I know it isn't a compiler, I was asking if it would work if I used CodeBlocks IDE and mingw64 i.o. MSys2 and mingw64

When I say "what did you do" means "what should i do to make it work by using CodeBlocks IDE and mingw64" or "what are comprehensivles steps I should do to install lapack package".

Notice, I just want my program to run and stop showing the undefined referrence error...

I know what is an IDE and a compiler... my problem is how to handle the libraries... could you or anybody guide with this, please? I.e. tell the steps to make the lapack be recognized and stop the error...
« Last Edit: February 13, 2020, 06:46:27 pm by Librarylinker »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Linking libraries (.lib fortran)
« Reply #12 on: February 13, 2020, 06:55:39 pm »
Build blas library using your GCC compiler and the lapack source code!

Or you could use the MSys2 MinGW64 bit environment and its Compiler and Libraries!
https://www.msys2.org/

This is not a proper website to help a newbie to solve off topic issues!

Or, you could post the build log! But, you are too lazy to do that!

Tim S.


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: Linking libraries (.lib fortran)
« Reply #13 on: February 13, 2020, 07:25:12 pm »
The libraries you are trying to use were designed for use by C or C++.

The functions do not have the trailing "_" wanted by FORTRAN!

Tim S.
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: Linking libraries (.lib fortran)
« Reply #14 on: February 13, 2020, 07:30:04 pm »
Please find a FORTRAN support website to help you learn how to use the lapack FORTRAN library without trying to use the C library version of it.

Tim S.
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