esnacc / esnacc-ng

A continuation of the Enhanced SNACC ASN.1 compiler - See http://mail.esnacc.org/mailman/listinfo/dev
http://esnacc.org
GNU General Public License v2.0
32 stars 30 forks source link

Build esnacc on MSVC 2017 #48

Closed momor10 closed 6 years ago

momor10 commented 6 years ago

im trying to build esnacc with msvc 2017 and msys2 on windows 10. i already managed to compile it using mingw. However i need to use esnacc (encode data in per and send uper udp stream) in a windows c++/qt application using msvc2017.

Using msys2 i managed to boot and configure esnacc using the following command:

bash ./boot.sh
bash ./configure LD=linker.exe

the resulting output:

configure: loading site script /usr/local/etc/config.site
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... no
checking whether make supports nested variables... no
checking for gcc... no
checking for cc... no
checking for cl.exe... cl.exe
checking whether the C compiler works... yes
checking for C compiler default output file name... conftest.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... obj
checking whether we are using the GNU C compiler... no
checking whether cl.exe accepts -g... yes
checking for cl.exe option to accept ISO C89... none needed
checking whether cl.exe understands -c and -o together... no
checking for style of include used by make... none
checking dependency style of /d/Projekte/esnacc-ng/compile cl.exe... none
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl.exe... cl.exe
checking whether we are using the GNU C++ compiler... no
checking whether cl.exe accepts -g... yes
checking dependency style of cl.exe... none
checking for python... /c/Python/Python27/python
checking for python version... 2.7
checking for python platform... win32
checking for python script directory... ${prefix}\Lib\site-packages
checking for python extension module directory... ${exec_prefix}\Lib\site-packages
checking how to run the C preprocessor... /d/Projekte/esnacc-ng/compile cl.exe -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... no
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... no
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... no
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for ar... no
checking for lib... lib
checking the archiver (lib) interface... lib
checking whether ln -s works... no, using cp -pR
checking for flex... flex
checking lex output file root... lex.yy
checking lex library... none needed
checking whether yytext is a pointer... no
checking for bison... bison -y
checking for a sed that does not truncate output... /usr/bin/sed
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for size_t... yes
checking for ANSI C header files... (cached) no
checking build system type... x86_64-pc-msys
checking host system type... x86_64-pc-msys
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for non-GNU ld... linker.exe
checking if the linker (linker.exe) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... no
checking for dumpbin... dumpbin
checking the name lister (dumpbin -symbols -headers) interface... MS dumpbin
checking the maximum length of command line arguments... 8192
checking how to convert x86_64-pc-msys file names to x86_64-pc-msys format... func_convert_file_noop
checking how to convert x86_64-pc-msys file names to toolchain format... func_convert_file_noop
checking for linker.exe option to reload object files... -r
checking for objdump... no
checking how to recognize dependent libraries... file_magic ^x86 archive import|^x86 DLL
checking for dlltool... no
checking how to associate runtime and link libraries... func_cygming_dll_for_implib_fallback
checking for archiver @FILE support... @
checking for strip... no
checking for ranlib... no
checking command to parse dumpbin -symbols -headers output from /d/Projekte/esnacc-ng/compile cl.exe object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... yes
checking for dlfcn.h... no
checking for objdir... .libs
checking for /d/Projekte/esnacc-ng/compile cl.exe option to produce PIC... -DDLL_EXPORT -DPIC
checking if /d/Projekte/esnacc-ng/compile cl.exe PIC flag -DDLL_EXPORT -DPIC works... yes
checking if /d/Projekte/esnacc-ng/compile cl.exe static flag  works... yes
checking if /d/Projekte/esnacc-ng/compile cl.exe supports -c -o file.obj... yes
checking if /d/Projekte/esnacc-ng/compile cl.exe supports -c -o file.obj... (cached) yes
checking whether the /d/Projekte/esnacc-ng/compile cl.exe linker (linker.exe) supports shared libraries... yes
checking dynamic linker characteristics... Win32 link.exe
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... no
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... cl.exe -E
checking whether the cl.exe linker (linker.exe) supports shared libraries... yes
checking for cl.exe option to produce PIC... -DDLL_EXPORT -DPIC
checking if cl.exe PIC flag -DDLL_EXPORT -DPIC works... yes
checking if cl.exe static flag  works... yes
checking if cl.exe supports -c -o file.obj... no
checking if cl.exe supports -c -o file.obj... (cached) no
checking whether the cl.exe linker (linker.exe) supports shared libraries... yes
checking dynamic linker characteristics... Win32 link.exe
checking how to hardcode library paths into programs... immediate
checking for pow in -lm... no
checking for strchr... yes
checking for getchar... yes
checking for memset... yes
checking for memcmp... yes
checking for memcpy... yes
checking windows.h usability... yes
checking windows.h presence... yes
checking for windows.h... yes
checking for C-compiler all-warnings support with -Wall... yes
checking for C-compiler extra-warnings support with -Wextra... no
checking for C++-compiler all-warnings support with -Wall... yes
checking for C++-compiler extra-warnings support with -Wextra... no
checking whether to build with code coverage support... no
checking for xsltproc... /usr/bin/xsltproc
checking for manpage docbook... http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

trying to compile it with jom or nmake will result in the following errors

PS D:\Projekte\esnacc-ng> nmake

Microsoft (R) Program Maintenance Utility, Version 14.14.26433.0
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

makefile(185) : fatal error U1001: Syntaxfehler: ungültiges Zeichen "\" in Makro
Stop.
PS D:\Projekte\esnacc-ng> jom
Error: Invalid macro invocation found in D:\Projekte\esnacc-ng\Makefile line 1387
PS D:\Projekte\esnacc-ng>

The docs say msvc 2013 is supported, however there is no step by step description on how to make it compile (using automake?)

apconole commented 6 years ago

Can you try using gnu make (I think it should come with msys2)?

momor10 commented 6 years ago

using make of msys2 (had to install by pacman -S make) it worked. the result: cxxasn1.lib however trying to link it with my project i get the following error: cxxasn1.lib(cxx_lib_libcxxasn1_la-asn-buf.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in in main.obj

my qt project file for the library:

LIBS += -L$$PWD/cxx-lib/libs/ -lcxxasn1

INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/cxx-lib/inc

HEADERS += $$PWD/MyAsnFile.h

SOURCES += $$PWD/MyAsnFile.cpp

DISTFILES += \
    $$PWD/cxx-lib/inc/snacc.h.in

going through the esnacc-ng\cxx-examples\automake.mk i dont see anything else that might be relevant putting in? did i miss something?

edit: tried using --enabled-shared and --enabled-static which both resulted in the same error when linking.

momor10 commented 6 years ago

while compiling i get the following warning: libtool: warning: undefined symbols not allowed in x86_64-pc-msys shared libraries; building static only

  1. that means it's trying to build the x64 version, right? how do i specify to build x86 ?
  2. is it possible to make it compile shared libraries also?
apconole commented 6 years ago

momor10 notifications@github.com writes:

while compiling i get the following warning: libtool: warning: undefined symbols not allowed in x86_64-pc-msys shared libraries; building static only

1 that means it's trying to build the x64 version, right? how do i specify to build x86 ? 2 is it possible to make it compile shared libraries also?

The ./configure should support the flag "--enable-shared" - does that not work?

For the windows build, it seems we do the following:

./configure CC=build-aux/cccl CXX=build-aux/cccl LD="which link" LIBS="-lws2_32 -liphlpapi"

Maybe that helps?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

momor10 commented 6 years ago

using: bash ./configure LD=linker.exe LIBS="-lws2_32 -liphlpapi" results in:

PS D:\Projekte\esnacc-ng> make
/usr/bin/make  all-am
make[1]: Entering directory '/d/Projekte/esnacc-ng'
compiler/esnacc.exe -C -mo `dirname cxx-lib/src/snaccrose.cpp` asn1specs/snaccrose.asn
make[1]: *** [Makefile:5099: cxx-lib/src/snaccrose.cpp] Error 127
make[1]: Leaving directory '/d/Projekte/esnacc-ng'
make: *** [Makefile:1371: all] Error 2

And bash ./configure CC=build-aux/cccl CXX=build-aux/cccl LD=linker.exe LIBS="-lws2_32 -liphlpapi" results in:

LINK : warning LNK4044: Nicht erkannte Option /I./compiler/core; wird ignoriert.
LINK : warning LNK4044: Nicht erkannte Option /I./c-lib/inc; wird ignoriert.
LINK : warning LNK4044: Nicht erkannte Option /I./compiler/back-ends; wird ignoriert.
LINK : warning LNK4044: Nicht erkannte Option /I.; wird ignoriert.
LINK : warning LNK4044: Nicht erkannte Option /DCOMPILER; wird ignoriert.
lt-esnacc.c
LINK : compiler/esnacc.exe wurde nicht gefunden oder beim letzten inkrementellen Linkvorgang nicht erstellt; vollständiger Link wird durchgeführt.
compiler/esnacc.exe -C -mo `dirname cxx-lib/src/snaccrose.cpp` asn1specs/snaccrose.asn
make[1]: *** [Makefile:5099: cxx-lib/src/snaccrose.cpp] Error 127
make[1]: Leaving directory '/d/Projekte/esnacc-ng'
make: *** [Makefile:1371: all] Error 2

The Error when trying to use the lib:

cxxasn1.lib(cxx_lib_libcxxasn1_la-snaccexcept.obj):-1: Fehler: LNK2038: Konflikt ermittelt für "RuntimeLibrary": Der Wert "MT_StaticRelease" stimmt nicht mit dem Wert "MD_DynamicRelease" in main.obj überein. on stackoverflow someone said (not to me):

The library and your project must be linked with the same settings with regards to the C Runtime Library. In your case one was linked against the CRT DLL (/MD) and the other was linked statically (/MT). You just need to make sure both match and this error will go away. source: https://stackoverflow.com/questions/28887001/lnk2038-mismatch-detected-for-runtimelibrary-value-mt-staticrelease-doesn

However im not sure how to find out what to do? do i need to compile esnacc differently? do i need to compile my project using the lib differently? how do i found which is linked how?

edit: even with --enabled-shared i will get an: libtool: warning: undefined symbols not allowed in x86_64-pc-msys shared libraries; building static only (im using the 32bit version of msys2)

edit2: after trying the -no-undefined because of the "libtool: warning: undefined symbols not allowed": bash ./configure LD=linker.exe --enable-shared --build=i686-pc-msys --host=i686-pc-msys make results in:

cl : Befehlszeile error D8021 : Ungültiges numerisches Argument /Wl,-DLL,-IMPLIB:cxx-lib/.libs/cxxasn1.dll.lib.
make[1]: *** [Makefile:1641: cxx-lib/libcxxasn1.la] Error 2
make[1]: Leaving directory '/d/Projekte/esnacc-ng'
make: *** [Makefile:1370: all] Error 2
momor10 commented 6 years ago

worked like that:

bash ./configure LD=linker.exe --enable-shared CFLAGS=-MD CXXFLAGS=-MD --build=i686-pc-msys --
host=i686-pc-msys
LIBS += -L$$PWD/cxx-lib/libs/ -lcxxasn1
LIBS += -L$$PWD/cxx-lib/libs/ -lcxxasn1rose
INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/cxx-lib/inc

HEADERS += $$PWD/CoopIts.h

SOURCES += $$PWD/CoopIts.cpp

QMAKE_CFLAGS_MT+=$$PWD/cxx-lib/inc
QMAKE_CXXFLAGS_MT+=$$PWD/cxx-lib/inc

this doesnt solve the problem about the shared libraries not being compiled. however now at least im able to use the static libraries in my msvc2017 qt Project. Just for anyone having the same problem.

thx @orgcandman for your help in both cases here and about the "syntax in the asn file" thread.

edit: i didnt test it yet, i only managed to compile and start the software without crashing. i hope there are no problems about solving it like that?

and still have a lot of linker warnings like: udpthread.obj:-1: Warnung: LNK4217: Lokal definiertes Symbol "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void))" wurde in "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_stringbuf<char,struct std::char_traits<char>,class std::allocator<char> >::str(void)const " (?str@?$basic_stringbuf@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ)-Funktion importiert.