3

I downloaded the FMUSDK and I want to compile the code. Unfortunately the build script is supposed to work with the Visual Studio C compiler, but I can't install/use it on my machine. Thus, I try to modify the script (and some parts of the code) to be able to compile it with the GCC. But I am completely new to compiling complex code (I usually just use gcc *.c -o outfile.exe)

Here is my problem: In some files there is a library linked with

 #pragma comment(lib, "libxml2.lib")

This does not work with GCC.

The lib can be found in ..\shared\parser\libxml2.lib with headers files in ..\shared\parser\libxml\

I call the build script with

fmusdk\fmu20\src\co_simulation>..\build_fmusim_cs_gcc.bat

The script then looks like this:

set SRC=main.c ..\shared\sim_support.c ..\shared\xmlVersionParser.c ..\shared\parser\XmlParser.cpp ..\shared\parser\XmlElement.cpp ..\shared\parser\XmlParserCApi.cpp
set INC=-I ..\shared\include -I ..\shared -I ..\shared\parser\libxml -I ..\shared\parser 
set LIB=-L ..\shared\include -L ..\shared -L ..\shared\parser\libxml -L ..\shared\parser 
set OPTIONS=-D FMI_COSIMULATION -D STANDALONE_XML_PARSER -D LIBXML_STATIC -v

g++ %INC% %OPTIONS% %SRC% %LIB% -lxml2 -o fmu20sim_cs.exe 

But I get the following error message:

c:/users/<username>/userprograms/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lxml2

I tried to use what I found on http://www.rapidtables.com/code/linux/gcc/gcc-l.htm, but I seems not to work.

Can someone help? What am I doing wrong? Under INC and LIB I put everything that looked helpful, but I have no idea what I am really doing there ...

I have also a logfile with the verbose output of the batch file. But I don't see how to upload it here :(

Best regards, Martin

HarryKane
  • 129
  • 3
  • 13
  • I think there must be xml2 library installed on your system too. maybe as another dependency , try to install libxml2 at first. – nullqube Nov 21 '17 at 10:34
  • But the library is already there. What else shall I do? – HarryKane Nov 21 '17 at 10:38
  • you sure? how you did check that? I don't mean the one you addressed at script (that's libxml) , and if you sure then maybe you can address it with fullpath -Lpath/to/xml2 – nullqube Nov 21 '17 at 10:40
  • Tried you this?: "For bug reports, **questions** or comments regarding the FMU SDK, please mail to fmu@QTronic.de." (I copied it just from the link you provided.) . – Scheff's Cat Nov 21 '17 at 10:44

2 Answers2

4

libxml2.lib is the example of (quite frequent) messing with library name conventions. Visual Studio uses the convention of adding .lib extension (this would be xml2.lib), GCC uses the convention of adding lib prefix and .a extension to library name (this would be libxml2.a).

According to GCC manual (https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Link-Options.html#Link-Options) you have two options:

  1. Change the library file name to the libxml2.a, because that is the file name GCC is looking for when given the -lxml2 option.

    The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a.

  2. Provide the full name of the library file , without -l (e.g. change -lxml2 to libxml2.lib in g++ command line), then the GCC will look for the given name exactly.

    A file name that does not end in a special recognized suffix is considered to name an object file or library. (Object files are distinguished from libraries by the linker according to the file contents.) If linking is done, these object files are used as input to the linker.

boorg
  • 146
  • 4
3

You should replace -lxml2 by -llibxml2.

Explaination, from Mingw :

Also note that the library names "lib<name>.a" and "lib<name>.lib" are not equivalent; if you have a library named according to the aberrant "lib<name>.lib" convention, it will not be found by an "-l<name>" specification -- if you cannot rename the library, you must use the form "-llib<name>" instead.

Mathieu
  • 8,840
  • 7
  • 32
  • 45