Woltan
Woltan

Reputation: 14023

Statically linking matio library using g++

How do you statically link matio, a library for reading mat-files, mainly used by matlab and octave into an executable?

If the file main.cpp holds matio functionality the compiler call

g++ -o main main.cpp -Imatio/include matio/lib/libmatio.a

fails with a bunch of error messages like: undefined reference to `inflateEnd'. This can be resolved by also adding zlib to the compiler call:

g++ -o main main.cpp -Imatio/include matio/lib/libmatio.a -lz

Now the error messages differ with something like undefined reference to `__intel_sse2_strlen'. So it appears that the zlib library is necessary for the comilation.

I now have the following questions:

  1. What do you need to do to statically link the matio library in an executable?
  2. Why do I need to add the zlib library even though I configured and compiled matio with ./configure --without-libz?

Upvotes: 1

Views: 1651

Answers (1)

tsnorri
tsnorri

Reputation: 2097

To build matio without zlib you apparently need to invoke configure with

./configure --with-zlib=no

(Checked this from configure.ac and config/matio_zlib.m4.)

In case you want to build matio with icc, Intel's developer pages tell that __intel_sse2_strlen is defined in libirc.a on Linux and libirc.lib on Windows.

To compile matio with the gcc do

./configure --with-zlib=no CC=gcc

afterwards, the matio library is statically linkable with the call posted in the question

Upvotes: 2

Related Questions