Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: cross-compiling czmq with fails #819

Closed
sappo opened this issue Nov 20, 2014 · 13 comments
Closed

Problem: cross-compiling czmq with fails #819

sappo opened this issue Nov 20, 2014 · 13 comments

Comments

@sappo
Copy link
Member

sappo commented Nov 20, 2014

Hi,
when I cross-compile czmq with MXE to mingw32 the compilation fails.

I use the following setup to configure czmq. The libzmq build is at ~/workspace/zeromq/cross_x86_64

$ PKG_CONFIG_PATH_x86_64_w64_mingw32="~/workspace/zeromq/cross_x86_64/lib/pkgconfig" ./configure --host=x86_64-w64-mingw32 --prefix=~/workspace/zeromq/cross_x86_64  --with-libzmq=~/workspace/zeromq/cross_x86_64

This is the result when I run make now.

$ make
...
  CC     src/src_libczmq_la-zactor.lo
In file included from src/../include/czmq.h:19:0,
                 from src/zactor.c:34:
src/../include/czmq_prelude.h:459:1: error: unknown type name 'uint64_t'
src/zactor.c:100:1: error: 'zactor_new' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes]
src/zactor.c:152:1: error: 'zactor_destroy' redeclared without dllimport attribute after being referenced with dll linkage [-Werror]
src/zactor.c:179:1: error: 'zactor_send' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes]
src/zactor.c:191:1: error: 'zactor_recv' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes]
src/zactor.c:201:1: error: 'zactor_is' redeclared without dllimport attribute after being referenced with dll linkage [-Werror]
src/zactor.c:214:1: error: 'zactor_resolve' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes]
src/zactor.c:229:1: error: 'zactor_sock' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes]
src/zactor.c:276:1: error: 'zactor_test' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes]
cc1: all warnings being treated as errors
make[1]: *** [src/src_libczmq_la-zactor.lo] Error 1
make[1]: Leaving directory `/home/ksapper/Workspace/zeromq/czmq'
make: *** [all-recursive] Error 1
@evoskuil
Copy link
Contributor

I just fixed up some issues in the VS builds. One of them might have been causing the dllimport errors on mingw. See f0b4801.

There remain two unresolved externals from the test build remaining in the VS builds. I can never seem to locate where the self-tests are exported.

czmq_selftest.obj : error LNK2019: unresolved external symbol _zgossip_test referenced in function _main
czmq_selftest.obj : error LNK2001: unresolved external symbol _zsys_allocs

Notice however that the second error is on zsys_allocs, which is in the same place as the first error you are seeing, on this line:

extern volatile uint64_t zsys_allocs;

Apparently uint64_t isn't defined in the mingw configuration, although it is in the VS build.

@sappo
Copy link
Member Author

sappo commented Nov 20, 2014

The uint64_t is only defined if mingw32 is not 428:# if (!defined (__MINGW32__)).

Sadly your pull request didn't fix the dllimport errror on mingw.

@evoskuil
Copy link
Contributor

I've patched the VS unresolved externals mentioned above, see #821. I don't see anything wrong with zactor. Seems like there's something extraneous in the mingw build.

@pijyoi
Copy link
Contributor

pijyoi commented Nov 21, 2014

I got a bit further in the compilation, past the dllimport error:

CFLAGS=-DLIBCZMQ_EXPORTS PKG_CONFIG_PATH_i686_pc_mingw32=$HOME/mingw32/lib/pkgconfig ./configure --prefix=$HOME/mingw32 --host=i686-pc-mingw32

According to czmq_prelude.h, nowadays FD_SETSIZE is automatically set to 1024, so we no longer need to include it in CFLAGS.

@pijyoi
Copy link
Contributor

pijyoi commented Nov 21, 2014

Apart from fixing some warnings in ziflist.c, two more flags are needed before the ./configure line.
LDFLAGS="-L$HOME/mingw32/lib" LIBS="-lzmq"

Not sure why these aren't automatic anymore.

@sappo
Copy link
Member Author

sappo commented Nov 21, 2014

@pijyoi that is just awfully complicated :(

If I fix the warnings in ziflist.c I do get the following error:

  CCLD     src/libczmq.la
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x2e0): undefined reference to `__imp_inet_addr'
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x2fb): undefined reference to `__imp_inet_addr'
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x38b): undefined reference to `__imp_htons'
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x3e5): undefined reference to `__imp_bind'
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x434): undefined reference to `__imp_getnameinfo'
/usr/bin/x86_64-w64-mingw32-ld: src/.libs/src_libczmq_la-zbeacon.o: bad reloc address 0x0 in section `.pdata'
collect2: error: ld returned 1 exit status
make[1]: *** [src/libczmq.la] Error 1
make[1]: Leaving directory `/mnt/DataStorage/workspace/zeromq/czmq'
make: *** [all-recursive] Error 1

Can you confirm this error or does czmq compile correctly with your configure modifications.

@pijyoi
Copy link
Contributor

pijyoi commented Nov 21, 2014

Yes, I got the same. There's another comment I left about the extra flags
needed. Even uglier.
On 22 Nov 2014 02:13, "Kevin Sapper" notifications@github.com wrote:

@pijyoi https://github.com/pijyoi that is just awfully complicated :(

If I fix the warnings in ziflist.c I do get the following error:

CCLD src/libczmq.la
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x2e0): undefined reference to __imp_inet_addr' src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x2fb): undefined reference to__imp_inet_addr'
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x38b): undefined reference to __imp_htons' src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x3e5): undefined reference to__imp_bind'
src/.libs/src_libczmq_la-zbeacon.o:zbeacon.c:(.text+0x434): undefined reference to __imp_getnameinfo' /usr/bin/x86_64-w64-mingw32-ld: src/.libs/src_libczmq_la-zbeacon.o: bad reloc address 0x0 in section.pdata'
collect2: error: ld returned 1 exit status
make[1]: *** [src/libczmq.la] Error 1
make[1]: Leaving directory `/mnt/DataStorage/workspace/zeromq/czmq'
make: *** [all-recursive] Error 1

Can you confirm this error or does czmq compile correctly with your
configure modifications.

Reply to this email directly or view it on GitHub
#819 (comment).

@sappo
Copy link
Member Author

sappo commented Nov 25, 2014

If I extend the LDFLAGS even further, it finally compiles:

LDFLAGS="-L$(MXE_HOME)/usr/x86_64-w64-mingw32/lib -lws2_32 -liphlpapi -lrpcrt4"

@pijyoi
Copy link
Contributor

pijyoi commented Nov 25, 2014

I thought master had since been patched so that LDFLAGS was no longer
required.

But even before the patch, the libs I need to add were only ws2_32 and zmq.
On 26 Nov 2014 01:07, "Kevin Sapper" notifications@github.com wrote:

If I extend the LDFLAGS even further, it finally compiles:

LDFLAGS="-L$(MXE_HOME)/usr/x86_64-w64-mingw32/lib -lws2_32 -liphlpapi -lrpcrt4"

Reply to this email directly or view it on GitHub
#819 (comment).

@sappo
Copy link
Member Author

sappo commented Nov 25, 2014

I guess this is due to the different hosts x86_64-w64-mingw32 vs i686_pc_mingw32.

@sappo
Copy link
Member Author

sappo commented Nov 26, 2014

@pijyoi are you currently able to cross compile libzmq with i686_pc_mingw32 because I do get the following error:

/home/ksapper/Workspace/zeromq/libzmq/tools/curve_keygen.cpp:42: undefined reference to `_imp__zmq_curve_keypair'
/home/ksapper/Workspace/zeromq/libzmq/tools/curve_keygen.cpp:43: undefined reference to `_imp__zmq_errno'

@pijyoi
Copy link
Contributor

pijyoi commented Nov 26, 2014

Yes, libzmq master compiles nicely.
./configure --prefix=$HOME/mingw32 --host=i686-pc-mingw32

For CZMQ, it's:
CFLAGS="-DLIBCZMQ_EXPORTS -D__USE_MINGW_ANSI_STDIO"
PKG_CONFIG_PATH_i686_pc_mingw32=$HOME/mingw32/lib/pkgconfig ./configure
--prefix=$HOME/mingw32 --host=i686-pc-mingw32

The __USE_MINGW_ANSI_STDIO allows the compilation to not warn (and fail)
when coming across C99 %zu format specifier that was used in ziflist.c

On Wed, Nov 26, 2014 at 8:09 PM, Kevin Sapper notifications@github.com
wrote:

@pijyoi https://github.com/pijyoi are you currently able to cross
compile libzmq with i686_pc_mingw32 because I do get the following error:

/home/ksapper/Workspace/zeromq/libzmq/tools/curve_keygen.cpp:42: undefined reference to _imp__zmq_curve_keypair' /home/ksapper/Workspace/zeromq/libzmq/tools/curve_keygen.cpp:43: undefined reference to_imp__zmq_errno'

Reply to this email directly or view it on GitHub
#819 (comment).

@pijyoi
Copy link
Contributor

pijyoi commented Nov 26, 2014

Looking at libtool, it has the following: pic_flag = " -DDLL_EXPORT -DPIC"
That explains why CZMQ needs -DLIBCZMQ_EXPORTS but libzmq doesn't.
i.e. As far as libtool is concerned, the standard define to use is DLL_EXPORT.

commit 5dc41fe dated 2013-04-08 changed testing against DLL_EXPORT to testing against LIBCZMQ_EXPORTS.

If the current behaviour is surprising for the unwary, perhaps we could do something like
#ifdef DLL_EXPORT
#define LIBCZMQ_EXPORTS
#endif

@sappo sappo closed this as completed Mar 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants