linker - Mingw static link libstdc++ -
for work purpose need produce shared library modelica file (.mo) , load in matlab. reasons, matlab uses different version of libstdc++-6 causes conflict 1 needed shared library.
here command line i'm using generate .o files. .mo file transformed c files.
gcc -falign-functions -msse2 -mfpmath=sse -iinclude/ -iinclude/fmi1 -i. -domc_model_prefix=genrou -domc_num_mixed_systems=0 -domc_num_linear_systems=0 -domc_num_nonlinear_systems=0 -domc_ndelay_expressions=0 -domc_nvar_string=0 -c -o genrou.o genrou.c
a bunch of .o files being genereted, , reasons of brevity ommit others, same.
and here problematic command line
g++ -shared -i. -o genrou.dll genrou_fmu.o genrou.o genrou_functions.o genrou_records.o genrou_01exo.o genrou_02nls.o genrou_03lsy.o genrou_04set.o genrou_05evt.o genrou_06inz.o genrou_07dly.o genrou_08bnd.o genrou_09alg.o genrou_10asr.o genrou_11mix.o genrou_12jac.o genrou_13opt.o genrou_14lnz.o genrou_15syn.o genrou_16dae.o genrou_init_fmu.o -iinclude/ -iinclude/fmi1 -i. -domc_model_prefix=genrou -domc_num_mixed_systems=0 -domc_num_linear_systems=0 -domc_num_nonlinear_systems=0 -domc_ndelay_expressions=0 -domc_nvar_string=0 -l"c:/users/simonz~1/appdata/local/temp/tmp7j8dix/genrou/win_fmu" -falign-functions -msse2 -mfpmath=sse -l"c:/openmodelica1.11.0-64bit//lib//omc" -wl,-rpath,"c:/openmodelica1.11.0-64bit//lib//omc" -static-libgcc -static-libstdc++ -lregex -lexpat -lomcgc -lpthread -fopenmp -loleaut32 -lz -lhdf5 -lsimulationruntimec -lomcgc -lexpat -lregex -static-libgcc -luuid -loleaut32 -lole32 -lws2_32 -llis -lumfpack -lklu -lcolamd -lbtf -lamd -lsundials_idas -lsundials_kinsol -lsundials_nvecserial -lipopt -lcoinmumps -lpthread -lm -lgfortranbegin -lgfortran -lmingw32 -lgcc_eh -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lopenblas -lcminpack -lwsock32 -lstdc++ -llis -wl,--kill-at
it leads linker problem, libstdc++ defined twise, once in libstdc++.a
, , other in libstdc++.dll.a
c:/openmodelica1.11.0-64bit/tools/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0\libstdc++.a(fstream-inst.o):(.text$_znst13basic_filebuficst11char_traitsiceec1ev[_znst13basic_filebuficst11char_traitsiceec1ev]+0x0): multiple definition of `std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf()' c:/openmodelica1.11.0-64bit/tools/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/libstdc++.dll.a(d002277.o):(.text+0x0): first defined here c:/openmodelica1.11.0-64bit/tools/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0\libstdc++.a(fstream-inst.o):(.text$_znst13basic_filebuficst11char_traitsicee5closeev[_znst13basic_filebuficst11char_traitsicee5closeev]+0x0): multiple definition of `std::basic_filebuf<char, std::char_traits<char> >::close()' c:/openmodelica1.11.0-64bit/tools/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/libstdc++.dll.a(d002264.o):(.text+0x0): first defined here c:/openmodelica1.11.0-64bit/tools/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0\libstdc++.a(fstream-inst.o):(.text$_znst13basic_filebuficst11char_traitsiceed1ev[_znst13basic_filebuficst11char_traitsiceed1ev]+0x0): multiple definition of `std::basic_filebuf<char, std::char_traits<char> >::~basic_filebuf()' c:/openmodelica1.11.0-64bit/tools/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/libstdc++.dll.a(d002281.o):(.text+0x0): first defined here c:/openmodelica1.11.0-64bit/tools/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0\libstdc++.a(fstream-inst.o):(.text$_znst13basic_filebuficst11char_traitsicee4openepkcst13_ios_openmode[_znst13basic_filebuficst11char_traitsicee4openepkcst13_ios_openmode]+0x0): multiple definition of `std::basic_filebuf<char, std::char_traits<char> >::open(char const*, std::_ios_openmode)' [several lines same 'multiple definition' omitted] collect2.exe: error: ld returned 1 exit status makefile:41: recipe target 'genrou_fmu' failed mingw32-make: *** [genrou_fmu] error 1
i checked in folder , both of files present. don't know how ended there though.
through use of omshell.exe
able few informations can modified
getlinker() "g++ -shared -xlinker --export-all-symbols -fpic" setlinkerflags("-static-libgcc -static-libstdc++ -lregex -lexpat -lomcgc -lpthread -fopenmp -loleaut32 -lz -lhdf5") true getlinkerflags() "-static-libgcc -static-libstdc++ -lregex -lexpat -lomcgc -lpthread -fopenmp -loleaut32 -lz -lhdf5" getcompiler() "gcc" getcflags() "${sim_or_dynload_opt_level} -falign-functions -msse2 -mfpmath=sse ${modelicausercflags}" getenvironmentvar("sim_or_dynload_opt_level") "" getenvironmentvar("modelicausercflags") "" getcxxcompiler() "g++" getcompilecommand() "g++"
you try buildmodelfmu(..., fmutype="me", platforms={"static"})
see if works better, in particular if change use setlinker("gcc")
, setlinkerflags(...)
.
otherwise, install linux vm (or ubuntu subsystem in windows) , cross-compile using platforms={"x86_64-w64-mingw32"}
(or i686 32-bit) use different mingw gcc version. final link command me using linux uses regular gcc , no -llibstd++
:
x86_64-w64-mingw32-gcc -shared -o m.dll m_fmu.o ... -flto -shared -static-libgcc -lm -wl,-bstatic -lpthread -wl,-bdynamic
wiki
Comments
Post a Comment