Compilation of plugins in Linux

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • mariza_unizar
    Junior Member
    • Feb 2015
    • 21

    Compilation of plugins in Linux

    Hi there,

    I'm trying to recompile the Neo-Hookean plugin from the web in my Linux machine (Ubuntu 18.04) in order to learn how to do it. In principle, it seems to be compiling, but the shared library is ~ 30 kB (while the one provided in /bin is ~ 2.2 MB). I'm using g++ (I tried with gcc too), with the flags suggested in the developer's manual

    g++ -Wall -fPIC -c FENeoHookeanPI.cpp -I/home/xx/opt_local/febio-2.8.0-sdk/sdk/include
    g++ -shared -Wl,-soname,libtest-ma.so -o libtest-ma.so FENeoHookeanPI.o


    I also tried to specifically point to the libraries under /home/xx/opt_local/febio-2.8.0-sdk/sdk/lib... but still nothing.

    Any suggestion? Is there any IDE that could help with this? (I tried with CLion but I have little experience with CMake).

    Thanks in advance!

    MA
  • mherron
    Developer
    • Aug 2016
    • 95

    #2
    Hi, sorry that it took a bit of time to get back to you on this issue. I was just able to get this to compile using the GNU compiler. The fact that your shared library is so small is definitely because you're not getting the static libraries from the SDK linked into it properly. This won't throw any errors at compile time, but if you try to import your library into FEBio, it'll complain about having undefined symbols.

    This is what I used to get this to compile correctly:

    g++ -fPIC -shared -o NeoHookeanPi.so *.cpp *.h -I/path/to/febio-2.8.0-sdk/sdk/include/ -L/path/to/febio-2.8.0-sdk/sdk/lib/ -lfebiomech_gcc64 -lfecore_gcc64

    I'm not sure how familiar you are with compiling C code, so here's a breakdown of that command. Feel free to skip this if it all makes sense to you already, though I would encourage you to start reading again at the bolded line below if you do skip some of this.

    The -fPIC and -shared flags are simply necessary to create a shared library.

    The -o flag tells the compiler that the next argument is the name of our output, which I've put as NeoHookeanPi.so.

    The *.cpp and *.h arguments are telling the compiler to compile every .cpp and .h file that it finds in your current directory. This is a little sloppy, and it might be better to specifically write out the filenames, but it works so long as you're in the right place.

    -I/path/to/febio-2.8.0-sdk/sdk/include/ tells the compiler to add that directory to the include path. You'll of course need to replace that placeholder path with your actual path.

    -L/path/to/febio-2.8.0-sdk/sdk/lib/ tells the linker to add that folder to the list of directories in which it searches for libraries. Again, replace the path with your actual path.

    Read from here, please.

    -lfebiomech_gcc64 -lfecore_gcc64 tells the linker to link to libfebiomech_gcc.a, and libfecore_gcc64.a. If you have specified a directory with your libraries in it with the -L flag (which was done in the previous argument), then you don't need to list out the full file names for the libraries. For each library, you start with a -l (<- that's a lower case L) followed by a truncated version of the filename, in which you remove "lib" from the front of the filename, and you remove the file's extension, in this case ".a". Also, because you are using the GNU compiler, you need to link with the libraries that end in _gcc64. The ones that end in _lnx64 were created with the Intel compiler, and you will end up with undefined symbols if you use them.

    One thing that is very important to remember is that the order in which you link libraries matters. I tend to forget this, and it causes me problems. You have to link libfebiomech_gcc.a before you link libfecore_gcc64.a or you will get undefined symbols errors when you try to run it.

    Hopefully that helps, let me know if you run into any more issues.

    Michael Herron

    Comment

    • mariza_unizar
      Junior Member
      • Feb 2015
      • 21

      #3
      Dear Michael,

      first of all thank you for your detailed response. It was very useful! I couldn't find any reference to this part (-lfebiomech_gcc64 -lfecore_gcc64) in the manual.

      I tried to run the code directly as you said and, at the beginning, it complained a bit:

      g++ -fPIC -shared -o NeoHookeanPi.so *.cpp *.h -I/home/xx/opt_local/febio-2.8.0-sdk/sdk/include -L/home/xx/opt_local/febio-2.8.0-sdk/sdk/lib -lfebiomech_gcc64 -lfecore_gcc64
      FEElasticMaterial.h:1:9: warning: #pragma once in main file
      #pragma once
      ^~~~
      FEElasticMaterial.h:2:10: fatal error: FESolidMaterial.h: No such file or directory
      #include "FESolidMaterial.h"
      ^~~~~~~~~~~~~~~~~~~
      compilation terminated.
      FENeoHookeanPI.h:1:9: warning: #pragma once in main file
      #pragma once
      ^~~~


      After removing from the compilation the call to the header files, it worked (with some warnings of course, which I guess are related to the standard of c++ used in each case...):

      g++ -fPIC -shared -o NeoHookeanPi.so FENeoHookeanPI.cpp FENeoHookeanPI.h -I/home/xx/opt_local/febio-2.8.0-sdk/sdk/include -L/home/xx/opt_local/febio-2.8.0-sdk/sdk/lib -lfebiomech_gcc64 -lfecore_gcc64
      FENeoHookeanPI.h:1:9: warning: #pragma once in main file
      #pragma once
      ^~~~


      Now, the shared library is around 1.2 MB. I'll let you know if it works as soon as I test it (I'm still learning how to do that... ).

      Thanks!

      MA

      Comment

      • mariza_unizar
        Junior Member
        • Feb 2015
        • 21

        #4
        Dear Michael,

        I linked the library using the febio.xml file and tried to load it into FEBio... but unsuccessfully.

        Success loading plugin libprestrain_lnx64.so (version 1.0.0)
        Failed loading plugin /home/xx/Desktop/neohookeanpi1/NeoHookeanPI/src/NeoHookeanPi.so
        Reason: Failed to load the file.

        dlopen failed: /home/xx/Desktop/neohookeanpi1/NeoHookeanPI/src/NeoHookeanPi.so: undefined symbol: GOMP_parallel_start



        Also, I have to say that directly compiling all the /src folder downloaded from the website failed. It contained 4 files: dllmain.cpp, FENeohookeanPI.cpp, FENeohookeanPI.h, FEElasticMaterial.h (this one was giving problems during compilation and I removed it from the folder as, in the end, is imported through sdk/include/FEBioMech).

        Still the shared library that I get is around 1.2 MB vs the 2.0 MB of the library provided under bin/lnx64.

        My g++ version is

        g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
        Copyright (C) 2017 Free Software Foundation, Inc.


        Perhaps I'm still missing some flags... but checking the doxygen documentation they are all included but -Wl,-soname,libshared.so (which I'm not sure is the problem...). Any hints on what could be happening?

        Thanks!

        MA

        Comment

        • mariza_unizar
          Junior Member
          • Feb 2015
          • 21

          #5
          Dear Michael,

          any insight in this front?

          I still couldn't manage to compile it properly.

          Thanks,

          MA

          Comment

          • mherron
            Developer
            • Aug 2016
            • 95

            #6
            I apologize for not getting back to you on this. I saw your first post on April 16th, but somehow missed your second post that day.

            I have been trying to replicate the problem that you are having, and I am unable to do so. The command that you posted on the 16th was missing one of the source files, dllmain.cpp. I was able to get it to both compile and import using the following command:

            g++ -fPIC -shared -o NeoHookeanPi.so FENeoHookeanPI.cpp FENeoHookeanPI.h dllmain.cpp -I/home/xx/FEBio-2.8.0/sdk/include -L/home/xx/FEBio-2.8.0/sdk/lib -lfebiomech_gcc64 -lfecore_gcc64

            Just so that you know, my library was also 1.2 MB. I think that the other library is larger because it was compiled using the intel compiler, and statically linked to the intel runtime libraries.

            I'm not sure what could have caused the problem that you mentioned. However, we just released version 2.9.0 of FEBio. I would recommend that you download the new SDK and the new version of FEBio and see if you are still having the same problem.

            Hopefully the new SDK gives you better results, but let me know if it doesn't.

            Thanks,

            Michael Herron

            Comment

            • mariza_unizar
              Junior Member
              • Feb 2015
              • 21

              #7
              Dear Michael,

              thank you for your reply. As you suggested, I installed FEBio2.9 and run

              g++ -fPIC -shared -o NeoHookeanPi.so FENeoHookeanPI.cpp FENeoHookeanPI.h dllmain.cpp -I/home/xx/FEBio-2.9.0/sdk/include -L/home/xx/FEBio-2.9.0/sdk/lib -lfebiomech_gcc64 -lfecore_gcc64

              FENeoHookeanPI.h:1:9: warning: #pragma once in main file
              #pragma once
              ^~~~


              It compiled giving a library of 1.3 MB.

              I tried to load it into FEBio 2.9 and it's giving me the same error:


              ================================================== =========================

              F I N I T E E L E M E N T S F O R B I O M E C H A N I C S

              --- v e r s i o n - 2 . 9 . 0 ---



              FEBio is a registered trademark.
              copyright (c) 2006-2019 - All rights reserved

              ================================================== =========================

              Failed loading plugin /home/xx/FEBio-2.9.0/febio_prestrain/libprestrain_lnx64.so
              Reason: Invalid SDK version.


              Failed loading plugin /home/xx/FEBio-2.9.0/plugins-ma/NeoHookeanPi.so
              Reason: Failed to load the file.

              dlopen failed: /home/xx/FEBio-2.9.0/plugins-ma/NeoHookeanPi.so: undefined symbol: GOMP_parallel


              Not only that, but it is also crashing the installation of the pre-strain plugin (I guess, I would need to recompile it... but, of course, I'm not able to compile the NeoHookean).

              Thanks

              MA

              P.S. This is the dynamic library I could compile
              src.zip

              Comment

              • mherron
                Developer
                • Aug 2016
                • 95

                #8
                The Invalid SDK version error that you are getting for the prestrain plugin is caused by using an outdated version of the plugin. We just released a new version of the plugin to go with the new version of FEBio. If you download the newest version of that plugin, it should solve that problem.

                I am unsure what is causing the issue that you have in with the NeoHookean plugin. I downloaded the version of the plugin that you compiled, and it worked for me. I was able to get it to import without errors, and I used it to successfully run the example problem that's included in the plugin download. I even downloaded and installed the version of FEBio from our website and it worked just fine there.

                I checked the shared library that you compiled for undefined symbols, and it is indeed missing GOMP_parallel. However, this symbol is defined in libiomp5.so, which should be located in the bin directory of your FEBio install. In fact, FEBio won't even launch without it. Your library should be able to find this symbol definition after FEBio loads libiomp5.so, which should happen before your plugin gets loaded.

                In short, it really should be working, and I don't know why it's not. I've spoken about the issue with our lead developer, Steve Maas, and he is also unsure what is causing the problem.

                I have tried using your plugin on both openSuse Leap 15.0 (my work machine) and Ubuntu 16.04 (my home machine), and it worked in both places. The only thing that I can think of is that there is some problem unique to the Ubuntu 18.04 release that is causing this error. So I'm going to install Ubuntu 18.04 on a virtual machine and see if I get the same error that you're getting. I probably won't be able to get to that today, and possibly not before the weekend, but I wanted to give you an update to let you know that I'm looking into the issue.

                Sorry that this has been such a difficult process. I will let you know what I find.

                Thanks,

                Michael Herron

                Comment

                • mherron
                  Developer
                  • Aug 2016
                  • 95

                  #9
                  I installed a fresh version of Ubuntu 18.04 on a VM, installed FEBio, and downloaded the plugin that you compiled. I was able to get it to import without any errors, and I was able to get it to successfully run the example problem.

                  I then used this command to compile the plugin on Ubuntu 18.04:

                  g++ -fPIC -shared -o NeoHookeanPi.so FENeoHookeanPI.cpp FENeoHookeanPI.h dllmain.cpp -I/home/xx/FEBio-2.9.0/sdk/include -L/home/xx/FEBio-2.9.0/sdk/lib -lfebiomech_gcc64 -lfecore_gcc64

                  It compiled, imported, and ran without any problems.

                  I was really hoping to find something for you with this Ubuntu install, but I can't replicate the problems that you're having.

                  At this point the only idea that I have is that you could possibly be trying to import the wrong file. As in perhaps you're pointing to a version other than the one that you sent here, because this one appears to work. I have no idea what could be causing these issues otherwise.

                  There's a possibility that something went wrong on your Ubuntu installation that's causing this problem, like some broken package or something, but I really don't know what it could be. I would recommend that you try this out on a fresh install of the OS. Try it in a virtual machine first, they're pretty easy to set up. You can install VirtualBox in Ubuntu with this command:

                  sudo apt install virtualbox

                  If you're unfamiliar with VMs, there's a pretty good tutorial on how to set up a VM with VirtualBox here. It'll take about 15 minutes to set up. When it comes time to choose a virtual hard drive type, I'd ignore that page's suggestion, and choose "Dynamically allocated" instead, since it's just a throw-away machine. Also, I wouldn't bother with the part at the end where he has you install the VirtualBox Guest Additions.

                  Good luck!

                  Michael Herron

                  Comment

                  • maryrose
                    Member
                    • May 2019
                    • 32

                    #10
                    Hi all,

                    Hope it's ok to add to this thread. I had a similar issue where my shared library was around 30 kB. The above solution worked and I am now able to successfully load the plugin. I also receive the warning:
                    FENeoHookeanPI.h:1:9: warning: #pragma once in main file#pragma once^~~~

                    When I try to run the example co01.feb file I receive the following:
                    Success loading plugin NeoHookeanPi.so (version 0.0.0)Reading file co01.feb ...FAILED!FATAL ERROR: invalid value "neohookeanpi" for attribute "material.type" (line 35)

                    Any suggestions for this?

                    Many thanks,
                    Maryrose

                    Comment

                    Working...
                    X
                    😀
                    😂
                    🥰
                    😘
                    🤢
                    😎
                    😞
                    😡
                    👍
                    👎