Recent

Author Topic: Linking libzmq to a portable app (windows and linux)  (Read 14316 times)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Linking libzmq to a portable app
« Reply #15 on: January 24, 2017, 08:01:52 pm »

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Linking libzmq to a portable app
« Reply #16 on: January 24, 2017, 08:16:38 pm »
Thank you hawardpc! Filtering none and Now I can see the messages!
Be mindful and excellent with each other.
https://github.com/cpicanco/

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Linking libzmq to a portable app
« Reply #17 on: January 24, 2017, 08:16:51 pm »
Quote
I must disagree, though, with your metaphorical extension about "art". I would rather say that, despite looking really hacky, static linking has indeed its own science. The complexity about something does not turns it into art.
Sometimes i love drama  :D Please forgive me for that..

What i meant to say is that mastering such subject is an art. Linking objects in the correct order to keep the linker happy, different linkers that are out there, compiling the (mostly c) library yourself to include or exclude those parts that you wish (with the need to understand c compilers, build/make files etc).

It is way beyond the scope of what the 'ordinay' user of Lazarus would expect is necessary. RAD stands for Rapid and not boring build files and understanding linkers :-)

Most already give up when there is a need to build binutils.

I don't mind you disagreeing though, as your opinion on the matter is just as valid. For me it is a form of art as it can't be learned from books and/or manuals alone (but the same is true for developing real life applications).

btw: time restriction is a very bad advisor. If currently you are truly bound by that, then please give up now before ending in pure frustration and try again when you have a bit more time on your hands.

Quote
I would really appreciate if someone could tell me how to get the full log of the messages window in lazarus.
I use FPC myself, so am not bothered by what Lazarus attempt to hide for me.

However, this wiki article should be able to get you further. If all else fails then right click on your message window, select copy all/original message and paste into a empty editor window. (edit: howardpc was ahead of me).

Thaddy

  • Hero Member
  • *****
  • Posts: 18944
  • Glad to be alive.
Re: Linking libzmq to a portable app
« Reply #18 on: January 24, 2017, 09:01:16 pm »
fwiw: truly static linking is (or at least can be) an art form. Don't expect things to work automagically in case you do not have experience.
Yup. It is not really an art form - but close - but it does require a thorough understanding of linkers and linker options. In many ways FPC hides that complexity for you.
We are spoiled.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Linking libzmq to a portable app
« Reply #19 on: January 24, 2017, 09:07:26 pm »
Quote
btw: time restriction is a very bad advisor. If currently you are truly bound by that, then please give up now before ending in pure frustration and try again when you have a bit more time on your hands.
Finally! Using the (once vanished) warnings and messages I was able to static link the library!
All I need to do was to:

delphizmq
1) rename all 'external libzmq' to 'external';
2) remove the first 'const' section containing the 'libzmq' constant;
3) include the following compiler directives:

{$LINKLIB stdc++}
{$LINKLIB gcc_s}
{$LINK /usr/local/lib/libzmq.a}   

libzmq
1) compile libzmq project with --static configuration

Of course, I need to test this on different machines. If you have a Debian8 machine and want to help, please download free-mtrix release and try to execute the 'experiment_runner' app (can be found here https://github.com/lacs-ufpa/free-mtrix/releases/tag/v0.1.2).
« Last Edit: January 24, 2017, 09:12:52 pm by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: [SOLVED] Linking libzmq to a portable app
« Reply #20 on: August 30, 2017, 08:10:36 pm »
I must update this. The following should work on linux with zmq master:

Quote
{$LINKLIB pthread}
{$LINKLIB m}
{$LINKLIB stdc++}
{$LINKLIB gcc_s}
{$LINKLIB zmq.a}
« Last Edit: August 31, 2017, 02:46:49 am by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Linking libzmq to a portable app (windows and linux)
« Reply #21 on: August 31, 2017, 02:48:49 am »
For linking libzmq on linux against the current master the following should work:

{$IFDEF LINUX}
  {$LINKLIB pthread}
  {$LINKLIB m}
  {$LINKLIB stdc++}
  {$LINKLIB gcc_s}
  {$LINKLIB zmq.a}
{$ENDIF} 

However, static linking on windows will not work with static builds (vs 2017) of libzmq:

// directive for libraries
{$IFDEF WINDOWS}
  {$LINKLIB libzmq.lib}
{$ENDIF}
// Error: Invalid DLL <libzmq.lib path>, Dos Header invalid.

{or}

// directive for object files
{$IFDEF WINDOWS}
  {$LINK libzmq.lib}
{$ENDIF}
// Error: Illegal COFF Magic while reading <libzmq.lib path>,

Maybe there is some sort of configuration I am not aware of while building those static libraries or linking them or worse, there is no free pascal support to static linking this kind of static library. I need more information...
Be mindful and excellent with each other.
https://github.com/cpicanco/

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Linking libzmq to a portable app (windows and linux)
« Reply #22 on: August 31, 2017, 08:09:15 am »
You should build static library of zmq with MSYS2 (under linux with mingw-w64 build tools) environment if you are targeting Windows OS.

FPC doesn't support libraries (.lib) built with Visual Studio environment.

Thaddy

  • Hero Member
  • *****
  • Posts: 18944
  • Glad to be alive.
Re: Linking libzmq to a portable app (windows and linux)
« Reply #23 on: August 31, 2017, 09:10:18 am »
You should build static library of zmq with MSYS2 (under linux with mingw-w64 build tools) environment if you are targeting Windows OS.

FPC doesn't support libraries (.lib) built with Visual Studio environment.
Although if you unpack the .lib, FPC will happily link to the COFF obj files....

But anyway the level of cpicanco's questions is "a bit hard to grasp  ;)" even for old hands like you and me.... :D

Code: Pascal  [Select][+][-]
  1.   {$LINKLIB pthread}  // no
  2.   {$LINKLIB m}  // no
  3.   {$LINKLIB stdc++} // no, bollocks
  4.   {$LINKLIB gcc_s} // no, more bollocks.
  5.  

You only need zmq itself

« Last Edit: August 31, 2017, 09:12:10 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Linking libzmq to a portable app (windows and linux)
« Reply #24 on: September 01, 2017, 09:04:59 pm »
Quote
Although if you unpack the .lib, FPC will happily link to the COFF obj files....

Seriously? I need to test that (Wait... Damn, I unninstalled vs)

Quote
Code: Pascal  [Select][+][-]
  1.   {$LINKLIB pthread}  // no
  2.   {$LINKLIB m}  // no
  3.   {$LINKLIB stdc++} // no, bollocks
  4.   {$LINKLIB gcc_s} // no, more bollocks.
  5.  

You only need zmq itself

Yep, better to use package-config and link to libzmq itself (if you do know how to do it). Otherwise, stick to the hardcoded stuff.
« Last Edit: September 01, 2017, 09:18:20 pm by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Linking libzmq to a portable app (windows and linux)
« Reply #25 on: September 01, 2017, 09:14:32 pm »
You should build static library of zmq with MSYS2 (under linux with mingw-w64 build tools) environment if you are targeting Windows OS.

I was trying to build 32 and 64 cross compilers (mingw-w64), no success. Bad environment setup I guess. mingw was not finding some of its own headers.

Todos:

1) learn how to write a makefile (just enough to adapt libzmq/builds/mingw32/Makefile.mingw32);
2) learn enough stuff about mingw-w64 cross compilers

Any recommendations??
« Last Edit: September 01, 2017, 09:28:01 pm by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

 

TinyPortal © 2005-2018