Adding Material Works on Windows, Not on Linux

For developers writing C++, Fortran, Java, code who have questions or comments to make.

Moderators: silvia, selimgunay, Moderators

edwardal
Posts: 20
Joined: Wed Aug 24, 2016 5:33 am
Location: Istituto Universitario di Studi Superiori (IUSS)

Adding Material Works on Windows, Not on Linux

Post by edwardal » Wed Feb 15, 2017 2:44 pm

I can build the .dll on Windows for the example material ElasticPPcpp** and FractureMaterial (from Po-Chien Hsiao's PhD thesis "Seismic Performance Evaluation of Concentrically Braced Frames", 2012). When I go to make the .so file in a Linux environment, the .so file is not recognized when I run OpenSees (for either material). All I get is "WARNING could not create uniaxialMaterial ElasticPPcpp(or FractureMaterial)".

The LD_LIBRARY_PATH was set to the directory containing the .so file (the same directory containing the .tcl input file) while executing OpenSees and the same error persisted. The rev. number of the code used to compile OpenSees.exe is the exact same as the rev. number used to make the .so file, so I do not think there is any issue there. The only thing that I can think of is a 32/64 bit compatibility issue. The version line in the header of OpenSees.exe reads "Version 2.5.0 (rev 6236) 32-Bit". The machine, however, is running 64 bit Linux (OpenSees.exe runs with normal materials, etc. with no issues). I tried making the .so with both 32 and 64 bit but neither is read by OpenSees when the material is called. I am not sure where to go from here and any help would be greatly appreciated.

Thanks,

Ed

### EDIT (16 FEB 2017 11:09 CET) ###
Both OpenSees.exe and ElasticPPcpp.so are 64 bit:

$ file OpenSees
OpenSees: ELF 64-bit LSB executable, x86-64,
version 1 (SYSV), dynamically linked,
interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32,
BuildID[sha1]=467e69fd193408a4a3c067a29ac3c4fb1e5befcd,
stripped, with debug_info

$ file ElasticPPcpp.so
ElasticPPcpp.so: ELF 64-bit LSB shared object, x86-64,
version 1 (SYSV), dynamically linked,
BuildID[sha1]=fb4af8082b0b5658557ff8fd4ea12fba8243b406,
not stripped, with debug_info
### END EDIT ###

### EDIT 2 (17 FEB 2017 15:53 CET) ###
The source of the problem seems to be in the SRC/material/uniaxial/TclModelBuilderUniaxialMaterialCommand.cpp file, the getLibraryFunction is not returning 0 to int res (line 2823). Upon further investigation of the getLibraryFunction in the SRC/api/packages.cpp, -1 is returned due to evaluation of *libHandle == NULL as true (line 311), as opposed to the evaluation of funcPtr == NULL as true (line 334). So despite it reading the .so file (as shown in the debugging log in the reply below) it appears that the library is still not being recognized.

The makefile, makefile.def, .cpp, and .h files are all taken directly from the svn (with the makefile.def modified so the OS_FLAG = -D_LINUX) and the .so file built fine with g++. At this point, I am completely out of ideas as to why this is happening. Any suggestions would be greatly appreciated.
### END EDIT 2 ###

** While building ElasticPPcpp.dll in Visual Studio 2015 I had an issue where in the first part of the .cpp file here:

>#ifdef _USRDLL
> #define OPS_Export extern "C" _declspec(dllexport)
>#elif _MACOSX
> #define OPS_Export extern "C" __attribute__((visibility("default")))
>#else
> #define OPS_Export extern "C"
>#endif

The #ifdef _USRDLL was not evaluated as "true" and the else cause would execute and cause the .dll to be unusable. To solve this, I simply commented out everything and forced the "#define OPS_Export extern "C" _declspec(dllexport)" to be read. I have no Idea why this was happening. The FractureMaterial had the same exact block of code, but would properly evaluate _USRDLL and build a usable .dll without having to comment out the other options. I am completely baffled by this, but maybe this is an indicator of something that would cause problems in the Linux environment?
Last edited by edwardal on Thu Feb 16, 2017 6:54 am, edited 2 times in total.

edwardal
Posts: 20
Joined: Wed Aug 24, 2016 5:33 am
Location: Istituto Universitario di Studi Superiori (IUSS)

Re: Adding Material Works on Windows, Not on Linux

Post by edwardal » Wed Feb 15, 2017 4:55 pm

I'm not sure if this will help or not, but here is the relevant part of the strace debugging log. Basically, the ElasticPPcpp.so file is read in the "...DEVELOPER/material/cpp/" directory (where OpenSees.exe is executed), mapped to a location, then unmapped, then the *same* file is read and mapped to the *same* location again, then unmapped from that location before the "WARNING could not create..." message is printed.

The log is as follows:

...[several failed attempts to find the ElasticPPcpp.so file returning -1]...

>open("/home/ed/OpenSees_6236/DEVELOPER/material/cpp/ElasticPPcpp.so", O_RDONLY|O_CLOEXEC) = 3
>read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\36\0\0\0\0\0\0"..., 832) = 832
>fstat(3, {st_mode=S_IFREG|0755, st_size=37896, ...}) = 0
>mmap(NULL, 2113824, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7098531000
>mprotect(0x7f7098535000, 2093056, PROT_NONE) = 0
>mmap(0x7f7098734000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f7098734000
>close(3) = 0
>munmap(0x7f7098531000, 2113824) = 0
>stat("ElasticPPcpp.so", {st_mode=S_IFREG|0755, st_size=37896, ...}) = 0
>open("/usr/lib/ElasticPPcpp.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
>open("/home/ed/OpenSees_6236/DEVELOPER/material/cpp/ElasticPPcpp.so", O_RDONLY|O_CLOEXEC) = 3
>read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\36\0\0\0\0\0\0"..., 832) = 832
>fstat(3, {st_mode=S_IFREG|0755, st_size=37896, ...}) = 0
>mmap(NULL, 2113824, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7098531000
>mprotect(0x7f7098535000, 2093056, PROT_NONE) = 0
>mmap(0x7f7098734000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f7098734000
>close(3) = 0
>munmap(0x7f7098531000, 2113824) = 0
>write(2, "WARNING could not create uniaxia"..., 42WARNING could not create uniaxialMaterial ) = 42
>write(2, "ElasticPPcpp", 12ElasticPPcpp) = 12
>write(2, "\n", 1
>) = 1

...

fmk
Site Admin
Posts: 5883
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: Adding Material Works on Windows, Not on Linux

Post by fmk » Thu Feb 16, 2017 9:25 pm

what variant of linux are you on?

edwardal
Posts: 20
Joined: Wed Aug 24, 2016 5:33 am
Location: Istituto Universitario di Studi Superiori (IUSS)

Re: Adding Material Works on Windows, Not on Linux

Post by edwardal » Fri Feb 17, 2017 4:29 am

Arch Linux, x86_64 with 32 and 64 bit gcc and libraries

The specific error that seems to be preventing the library from loading is:

dlerror() = /tmp/ElasticPPcpp.so: undefined symbol: _ZN16UniaxialMaterial11setResponseEPPKciR10OPS_Stream

Doing $ nm -D ElasticPPcpp.so shows that there are a lot of undefined objects in the .so file, so maybe something is wrong with making the .so file. I've tried with different rev. numbers (and recompiling OpenSees for that rev.) and that doesn't seem to work either.

Here is a link to the result of $ nm -D ElasticPPcpp.so
http://pastebin.com/xBEmz7a1

TPdct
Posts: 43
Joined: Thu Jan 21, 2016 5:51 am
Location: Dalian University of Technology

Re: Adding Material Works on Windows, Not on Linux

Post by TPdct » Sat Feb 18, 2017 5:06 pm

Have you successfully built original version of OpenSees on your linux machine?

edwardal
Posts: 20
Joined: Wed Aug 24, 2016 5:33 am
Location: Istituto Universitario di Studi Superiori (IUSS)

Re: Adding Material Works on Windows, Not on Linux

Post by edwardal » Sat Feb 18, 2017 6:36 pm

Yes, right now I'm working with rev 6248. OpenSees builds successfully and runs models which make use of only standard features, but will not load the shared library (compiled for the same revision). I've experienced the same problem with any previous revisions that I've built as well.

fmk
Site Admin
Posts: 5883
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: Adding Material Works on Windows, Not on Linux

Post by fmk » Thu Feb 23, 2017 9:28 am

i just installed a new version of ubuntu and built OpenSees from svn .. the example you are citing works fine out of the box .. i had to change the Makefile.def in DEVELOPER to point to linux (which you already have done if you are getting the .so) and i had to set a LD_LIBRARY_PATH to include the directory, i.e. for running in the particular example directory i just added ./ to the path.

edwardal
Posts: 20
Joined: Wed Aug 24, 2016 5:33 am
Location: Istituto Universitario di Studi Superiori (IUSS)

Re: Adding Material Works on Windows, Not on Linux

Post by edwardal » Thu Feb 23, 2017 10:13 am

Thanks for the reply, fmk. Unfortunately, I have tried that and it is still not working. Could somebody with a working version of the ElasticPPcpp.so please enter the following command to see if the library contains undefined symbols like mine?

$ nm -D ElasticPPcpp.so

The link to my results (as posted above) is here: http://pastebin.com/xBEmz7a1
The U indicates that the symbol is undefined (which a lot of the symbols are for me) but I am not sure if it supposed to be like this or not.

Thanks in advance.

fmk
Site Admin
Posts: 5883
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: Adding Material Works on Windows, Not on Linux

Post by fmk » Thu Feb 23, 2017 11:35 am

here is what i get .. the undefines are fine, they exist in the application .. what the program is looking for when it loads the .so is the OPS_ElasticPPcpp ..
if this is not there this is your issue .. if it is there it is not loading the library file

00000000002040c0 B __bss_start
U __cxa_atexit
w __cxa_finalize
U __cxa_guard_abort
U __cxa_guard_acquire
U __cxa_guard_release
00000000002040c0 D _edata
0000000000204128 B _end
0000000000002ffc T _fini
w __gmon_start__
U __gxx_personality_v0
0000000000001de8 T _init
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w _Jv_RegisterClasses
0000000000002060 T OPS_ElasticPPcpp
U opserrPtr
U ops_getdoubleinput_
U ops_getintinput_
U __stack_chk_fail
U _Unwind_Resume
U _ZdlPv
000000000000263a T _ZN12ElasticPPcpp10getTangentEv
000000000000264e T _ZN12ElasticPPcpp11commitStateEv
00000000000027e0 T _ZN12ElasticPPcpp13revertToStartEv
00000000000024b2 T _ZN12ElasticPPcpp14setTrialStrainEdd
0000000000002fe8 W _ZN12ElasticPPcpp17getInitialTangentEv
000000000000279a T _ZN12ElasticPPcpp18revertToLastCommitEv
0000000000002dcc T _ZN12ElasticPPcpp5PrintER10OPS_Streami
000000000000285e T _ZN12ElasticPPcpp7getCopyEv
0000000000002b52 T _ZN12ElasticPPcpp8recvSelfEiR7ChannelR16FEM_ObjectBroker
00000000000028fa T _ZN12ElasticPPcpp8sendSelfEiR7Channel
0000000000002612 T _ZN12ElasticPPcpp9getStrainEv
0000000000002626 T _ZN12ElasticPPcpp9getStressEv
0000000000002232 T _ZN12ElasticPPcppC1Eidd
0000000000002342 T _ZN12ElasticPPcppC1Ev
0000000000002232 T _ZN12ElasticPPcppC2Eidd
0000000000002342 T _ZN12ElasticPPcppC2Ev
0000000000002486 T _ZN12ElasticPPcppD0Ev
0000000000002428 T _ZN12ElasticPPcppD1Ev
0000000000002428 T _ZN12ElasticPPcppD2Ev
U _ZN12TaggedObject6setTagEi
U _ZN13MovableObject11getVariableEPKcR11Information
U _ZN13MovableObject11setVariableEPKcR11Information
U _ZN13MovableObject12setParameterEPPKciR9Parameter
U _ZN13MovableObject15updateParameterEiR11Information
U _ZN13MovableObject17activateParameterEi
U _ZN16UniaxialMaterial11getResponseEiR11Information
U _ZN16UniaxialMaterial11setResponseEPPKciR10OPS_Stream
U _ZN16UniaxialMaterial13getStrainRateEv
U _ZN16UniaxialMaterial14getDampTangentEv
U _ZN16UniaxialMaterial14setTrialStrainEddd
U _ZN16UniaxialMaterial17commitSensitivityEdii
U _ZN16UniaxialMaterial17getRhoSensitivityEi
U _ZN16UniaxialMaterial20getStrainSensitivityEi
U _ZN16UniaxialMaterial20getStressSensitivityEib
U _ZN16UniaxialMaterial21getTangentSensitivityEi
U _ZN16UniaxialMaterial25getDampTangentSensitivityEi
U _ZN16UniaxialMaterial28getInitialTangentSensitivityEi
U _ZN16UniaxialMaterial6getRhoEv
U _ZN16UniaxialMaterial7getCopyEP23SectionForceDeformation
U _ZN16UniaxialMaterial8setTrialEddRdS0_S0_d
U _ZN16UniaxialMaterial8setTrialEdRdS0_d
0000000000002fd8 W _ZN16UniaxialMaterial9hasFailedEv
U _ZN16UniaxialMaterialC2Eii
U _ZN16UniaxialMaterialD2Ev
U _ZN6VectorC1Ei
0000000000002faa W _ZN6VectorclEi
U _ZN6VectorD1Ev
U _ZN8Material22getResponseSensitivityEiiR11Information
0000000000002fcc W _ZN8Material6updateEv
0000000000002f98 W _ZNK12TaggedObject6getTagEv
U _ZNK13MovableObject12getClassTypeEv
U _ZNK13MovableObject8getDbTagEv
U _Znwm
0000000000002dc3 T _ZThn16_N12ElasticPPcpp8recvSelfEiR7ChannelR16FEM_ObjectBroker
0000000000002b49 T _ZThn16_N12ElasticPPcpp8sendSelfEiR7Channel
00000000000024ac T _ZThn16_N12ElasticPPcppD0Ev
000000000000247f T _ZThn16_N12ElasticPPcppD1Ev
0000000000203db8 V _ZTI12ElasticPPcpp
U _ZTI16UniaxialMaterial
00000000000031c8 V _ZTS12ElasticPPcpp
0000000000203c40 V _ZTV12ElasticPPcpp
U _ZTVN10__cxxabiv120__si_class_type_infoE

fmk
Site Admin
Posts: 5883
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: Adding Material Works on Windows, Not on Linux

Post by fmk » Thu Feb 23, 2017 11:41 am

as you are on linux you have built the application .. go the SRC/api direcory and edit the packages.cpp file ..
around line 294 look for this block of code
if (*libHandle == NULL) {
delete [] localLibName;
return -1; // no lib exists
}
before the delete put the following line of code
opserr << "Could not find file: " << localLibName << endln;

and recompile and then run our example

edwardal
Posts: 20
Joined: Wed Aug 24, 2016 5:33 am
Location: Istituto Universitario di Studi Superiori (IUSS)

Re: Adding Material Works on Windows, Not on Linux

Post by edwardal » Mon Mar 13, 2017 4:47 pm

It seems to be a compiling issue with Arch Linux. I compiled it on a CentOS machine (using the exact same files) and it works fine. I don't know how to explain it, but now that I have a working version I am no longer going to spend time troubleshooting the Arch Linux issue. Thank you for your time and suggestions.

nilz
Posts: 34
Joined: Sat Nov 12, 2016 7:03 am
Location: Ferdowsi university of mashhad

Re: Adding Material Works on Windows, Not on Linux

Post by nilz » Sun Dec 17, 2017 2:40 am

Dear edwardal,
I want to use FractureMaterial from Po-Chien Hsiao's PhD thesis "Seismic Performance Evaluation of Concentrically Braced Frames", 2012.
What should I do?
I must implement the c++ code into Opensees or is there another way?
please help me.

nilz
Posts: 34
Joined: Sat Nov 12, 2016 7:03 am
Location: Ferdowsi university of mashhad

Re: Adding Material Works on Windows, Not on Linux

Post by nilz » Tue Jan 16, 2018 8:27 am

Dears fmk and edwardal
Is the code in Hiao's thesis perfect and working properly? or not?
because i want to implement this code to Opensees, I am not sure about it, please help me.
best regards

difrex
Posts: 1
Joined: Thu Jan 18, 2018 2:42 am
Contact:

Re: Adding Material Works on Windows, Not on Linux

Post by difrex » Thu Jan 18, 2018 2:47 am

We are one of the best reactor simulation software provider in india. Our mission is to serve clients worldwide with the fastest, assured and most comprehensive reactor services and solutions in industry;

nilz
Posts: 34
Joined: Sat Nov 12, 2016 7:03 am
Location: Ferdowsi university of mashhad

Re: Adding Material Works on Windows, Not on Linux

Post by nilz » Mon Jan 22, 2018 11:53 am

difrex wrote:
> http://www.difrex.com/
What is this link about?

Post Reply