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

undefined reference in mingw when link static library. #3318

Closed
o-u-p opened this issue Dec 4, 2018 · 7 comments
Closed

undefined reference in mingw when link static library. #3318

o-u-p opened this issue Dec 4, 2018 · 7 comments

Comments

@o-u-p
Copy link

o-u-p commented Dec 4, 2018

Please use this template for reporting suspected bugs or requests for help.

Issue description

I'm trying to compile a static libzmq.a in windows using mingw, I tried both the configure and Makefile.mingw32 file and got libzmq.a, but neither woked, here is the output:

../../../lib/libuc_protocol.a(context.cpp.obj):context.cpp:(.text+0x3c7):
undefined reference to `__imp_zmq_ctx_term'

../../../lib/libuc_protocol.a(context.cpp.obj):context.cpp:(.text+0xa03): undefined reference to __imp_zmq_ctx_new' ../../../lib/libuc_protocol.a(poller.cpp.obj):poller.cpp:(.text+0x682): undefined reference to __imp_zmq_poll' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x368): undefined reference to __imp_zmq_bind' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x408): undefined reference to __imp_zmq_connect' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x49a): undefined reference to __imp_zmq_setsockopt' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x4cb): undefined reference to __imp_zmq_setsockopt' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x500): undefined reference to __imp_zmq_setsockopt' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x532): undefined reference to __imp_zmq_setsockopt' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x5a3): undefined reference to __imp_zmq_setsockopt' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x623): more undefined references to __imp_zmq_setsockopt' follow ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x9c7): undefined reference to __imp_zmq_close' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x1306): undefined reference to __imp_zmq_setsockopt' ../../../lib/libuc_protocol.a(socket.cpp.obj):socket.cpp:(.text+0x1571): undefined reference to __imp_zmq_socket' ../../../lib/libuc_protocol.a(worker.cpp.obj):worker.cpp:(.text+0x521): undefined reference to __imp_zmq_proxy_steerable' ../../../lib/libuc_protocol.a(zeromq.cpp.obj):zeromq.cpp:(.text+0x31a): undefined reference to __imp_zmq_errno' ../../../lib/libuc_protocol.a(certificate.cpp.obj):certificate.cpp:(.text+0x3a6): undefined reference to __imp_zmq_curve_public' ../../../lib/libuc_protocol.a(certificate.cpp.obj):certificate.cpp:(.text+0x685): undefined reference to __imp_zmq_curve_keypair' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x32e): undefined reference to __imp_zmq_msg_init_size' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x345): undefined reference to __imp_zmq_msg_data' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x372): undefined reference to __imp_zmq_msg_init' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x3dd): undefined reference to __imp_zmq_getsockopt' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x414): undefined reference to __imp_zmq_msg_size' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x420): undefined reference to __imp_zmq_msg_data' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x4e4): undefined reference to __imp_zmq_recvmsg' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x512): undefined reference to __imp_zmq_getsockopt' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x592): undefined reference to __imp_zmq_sendmsg' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x5f7): undefined reference to __imp_zmq_msg_close' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x696): undefined reference to __imp_zmq_msg_close' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x714): undefined reference to __imp_zmq_msg_init_size' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x72c): undefined reference to __imp_zmq_msg_data' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x765): undefined reference to __imp_zmq_msg_init' ../../../lib/libuc_protocol.a(frame.cpp.obj):frame.cpp:(.text+0x7ce): undefined reference to __imp_zmq_msg_init'

--

Environment

  • libzmq version (commit hash if unreleased): zeromq-4.3.0
  • OS: windows 64bit

Minimal test code / Steps to reproduce the issue

  1. what I tried in Makefile.mingw32

all: libzmq.a

perf: inproc_lat.exe inproc_thr.exe local_lat.exe local_thr.exe remote_lat.exe remote_thr.exe

libzmq.dll: $(OBJS)
g++ -shared -static -O2 -s -o $@ $^ -Wl,--out-implib,$@.a $(LIBS)

libzmq.a: $(OBJS)
ar cr $@ $?

What's the actual result? (include assertion message & call stack if applicable)

undefiend reference

What's the expected result?

should export correct libzmq.a

@o-u-p o-u-p changed the title undefined reference in mingw when compile static library. undefined reference in mingw when link static library. Dec 4, 2018
@sigiesec
Copy link
Member

sigiesec commented Dec 9, 2018

You need to define ZMQ_STATIC when building your application/library.

@sigiesec
Copy link
Member

@o-u-p Were you able to resolve your build problem?

@PunshiB
Copy link

PunshiB commented Jan 15, 2019

@sigiesec Hi , even I am getting the same issue. I didn't understand "define ZMQ_STATIC". Do you mean I need to set something like cmake -G"Visual Studio 14 Win64" -DZMQ_STATIC=1 -DENABLE-DRAFTS=no CMakeLists.txt'. I tried building like above but it didn't worked , what value should I set to ZMQ_STATIC ?

@PunshiB
Copy link

PunshiB commented Jan 15, 2019

@sigiesec Also I notice that running "C:\Program Files\CMake\bin\cmake.exe" -G"Visual Studio 14 Win64" -DZMQ_STATIC=1 -DLIBZMQ_INCLUDE_DIRS="C:\ZeroMQ\libzmq\include" -DLIBZMQ_LIBRARIES="C:\ZeroMQ\libzmq\builds\cmake\lib\Debug\libzmq-v140-mt-gd-4_3_1.lib" -DENABLE-DRAFTS=no CMakeLists.txt "C:\Program Files\czmq"'. gives


-- Selecting Windows SDK version  to target Windows 10.0.14393.
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
fatal: not a git repository (or any of the parent directories): .git
-- git workspace root [128]:
-- Looking for linux/wireless.h
-- Looking for linux/wireless.h - not found
-- Looking for net/if_media.h
-- Looking for net/if_media.h - not found
-- Looking for getifaddrs
-- Looking for getifaddrs - not found
-- Looking for freeifaddrs
-- Looking for freeifaddrs - not found
-- Looking for include files sys/socket.h, net/if.h
-- Looking for include files sys/socket.h, net/if.h - not found
-- Found LIBZMQ: C:/ZeroMQ/libzmq/builds/cmake/lib/Debug/libzmq-v140-mt-gd-4_3_1.lib
-- Could NOT find UUID (missing: UUID_INCLUDE_DIRS)
-- Could NOT find SYSTEMD (missing: SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS)
-- Could NOT find LZ4 (missing: LZ4_LIBRARIES)
-- Could NOT find LIBCURL (missing: LIBCURL_LIBRARIES)
-- Detected CZMQ Version - 4.2.0
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE

-- ******************* Configuration Summary *******************
-- General:
--   Version           :   4.2.0
--   System            :   Windows
--   C compiler        :   C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
--   Debug C flags     :   /MDd /Zi /Ob0 /Od /RTC1 /DWIN32 /D_WINDOWS /W3 -std=gnu99
--   Release C flags   :   -O3 /DWIN32 /D_WINDOWS /W3 -std=gnu99
--   Build type        :   Release
--   Static build      :   ON
--   Shared build      :   ON
--   Draft API         :   No
--
-- Dependencies:
-- The following OPTIONAL packages have been found:

 * Threads

-- The following REQUIRED packages have been found:

 * libzmq

-- The following OPTIONAL packages have not been found:

 * uuid
 * systemd
 * lz4
 * libcurl

--
-- Install:
--   Install prefix    :C:/Program Files/czmq
--
-- ************************* Options ***************************
-- Options:
--   Use the Draft API (default = yes):
--   -DENABLE-DRAFTS=[yes|no]
--
-- *************************************************************
-- Configuration complete! Now procced with:
--   'make'                compile the project
--   'make test'           run the project's selftest
--   'make install'        install the project to C:/Program Files/czmq
--
-- Further options are:
--   'ctest -T memcheck'   run the project's selftest with
--                         valgrind to check for memory leaks
--
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    ENABLE-DRAFTS
    ZMQ_STATIC


-- Build files have been written to: C:/Program Files/czmq/builds/cmake

It shows ZMQ_STATIC not used so am I doing something wrong here?

@sigiesec
Copy link
Member

ZMQ_STATIC must be defined when calling the compiler, not cmake. So within cmake, add_definitions or target_compile_definitions would need to be called. I am not familiar with building czmq (this is more a question towards the czmq repo), so I don't know how the czmq can be configured such that it defines ZMQ_STATIC.

@PunshiB
Copy link

PunshiB commented Jan 22, 2019

Ok thanks I was able to get my work done using msi installer ..

@stale
Copy link

stale bot commented Jan 22, 2020

This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.

@stale stale bot added the stale label Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants