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

fix semi-static build flags for Win32/MSYS2 #1032

Closed
wants to merge 1 commit into from

Conversation

tothi
Copy link

@tothi tothi commented May 23, 2020

Signed-off-by: tothi [email protected]

@@ -57,6 +57,8 @@ if(BUILD_STATIC)
set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lcrypt32")
# And sockets
set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lws2_32")
# And others
set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lp11-kit -lidn2 -lunistring")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately breaks some setups, including ours. Are these optional dependencies of GnuTLS?

@@ -130,7 +132,7 @@ if(BUILD_STATIC_GCC)
set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -Wl,-z -Wl,muldefs -Wl,-Bstatic -ltsan -Wl,-Bdynamic -ldl -lm")
endif()
if(WIN32)
set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt")
set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pthread isn't used on Windows. Why was this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk exactly, but without pthread linking of convperf.exe fails in my setup (idk what is it and/or why it is needed):

[ 92%] Building CXX object tests/perf/CMakeFiles/fbperf.dir/__/__/vncviewer/Surface_Win32.cxx.obj
[ 93%] Linking CXX executable fbperf.exe
[ 93%] Built target fbperf
Scanning dependencies of target decperf
[ 94%] Building CXX object tests/perf/CMakeFiles/decperf.dir/decperf.cxx.obj
[ 94%] Linking CXX executable decperf.exe
[ 94%] Built target decperf
Scanning dependencies of target convperf
[ 95%] Building CXX object tests/perf/CMakeFiles/convperf.dir/convperf.cxx.obj
[ 95%] Linking CXX executable convperf.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/libgcc_eh.a(emutls.o):(.text+0x71): undefined reference to `pthread_key_create'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/libgcc_eh.a(emutls.o):(.text+0xad): undefined reference to `pthread_getspecific'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/libgcc_eh.a(emutls.o):(.text+0xf7): undefined reference to `pthread_once'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/libgcc_eh.a(emutls.o):(.text+0x157): undefined reference to `pthread_setspecific'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/libgcc_eh.a(emutls.o):(.text+0x21f): undefined reference to `pthread_setspecific'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [tests/perf/CMakeFiles/convperf.dir/build.make:110: tests/perf/convperf.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:979: tests/perf/CMakeFiles/convperf.dir/all] Error 2
make: *** [Makefile:150: all] Error 2

building on Windows 10 using MSYS2 (Mingw64).

@bphinz
Copy link
Member

bphinz commented May 31, 2020 via email

@bphinz
Copy link
Member

bphinz commented May 31, 2020

Sorry, slight correction - here are the changes that I make:

--- a/cmake/StaticBuild.cmake	2019-12-20 02:02:02.000000000 -0500
+++ b/cmake/StaticBuild.cmake	2019-12-22 13:34:57.350524347 -0500
@@ -23,7 +23,7 @@
 
   # gettext is included in libc on many unix systems
   if(NOT LIBC_HAS_DGETTEXT)
-    set(GETTEXT_LIBRARIES "-Wl,-Bstatic -lintl -liconv -Wl,-Bdynamic")
+    set(GETTEXT_LIBRARIES "-Wl,-Bstatic -lidn2 -lintl -lunistring -liconv -Wl,-Bdynamic")
     if(APPLE)
       set(GETTEXT_LIBRARIES "${GETTEXT_LIBRARIES} -framework Carbon")
     endif()
@@ -130,7 +130,7 @@
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -Wl,-z -Wl,muldefs -Wl,-Bstatic -ltsan -Wl,-Bdynamic -ldl -lm")
   endif()
   if(WIN32)
-    set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt")
+    set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread")
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -luser32 -lkernel32 -ladvapi32 -lshell32")
     # mingw has some fun circular dependencies that requires us to link
     # these things again

It's GETTEXT that I need to add those libs to, not GNUTLS

@tothi
Copy link
Author

tothi commented May 31, 2020

ok, trying to make this clearer: why i had to include these flags.

used MSYS2 platform for building on Windows 10, mingw64 environment exactly.

tried to follow the guidelines in BUILDING.txt file, prepared the config with cmake -G "MSYS Makefiles" -DBUILD_STATIC=1 ..:

-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.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:/msys64/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_BUILD_TYPE = Release
-- VERSION = 1.10.80
-- BUILD_TIMESTAMP = 2020-05-31 15:50
-- 64-bit build
-- Performing Test HAVE_ACTIVE_DESKTOP_H
-- Performing Test HAVE_ACTIVE_DESKTOP_H - Success
-- Performing Test HAVE_ACTIVE_DESKTOP_L
-- Performing Test HAVE_ACTIVE_DESKTOP_L - Success
-- Found ZLIB: C:/msys64/mingw64/lib/libz.dll.a (found version "1.2.11")
-- Found Gettext: C:/msys64/mingw64/bin/msgmerge.exe (found version "0.19.8.1")
-- Performing Test ICONV_HAVE_WERROR
-- Performing Test ICONV_HAVE_WERROR - Success
-- Performing Test ICONV_SECOND_ARGUMENT_IS_CONST
-- Performing Test ICONV_SECOND_ARGUMENT_IS_CONST - Failed
-- Found Iconv: C:/msys64/mingw64/lib/libiconv.dll.a
-- Looking for dgettext
-- Looking for dgettext - not found
-- Looking for dgettext in C:/msys64/mingw64/lib/libintl.dll.a
-- Looking for dgettext in C:/msys64/mingw64/lib/libintl.dll.a - found
-- Found JPEG: C:/msys64/mingw64/lib/libjpeg.dll.a (found version "80")
-- Performing Test FOUND_LIBJPEG_TURBO
-- Performing Test FOUND_LIBJPEG_TURBO - Success
-- Found FLTK: C:/msys64/mingw64/lib/libfltk_images.dll.a;C:/msys64/mingw64/lib/libfltk.dll.a
-- Found GnuTLS: C:/msys64/mingw64/lib/libgnutls.dll.a
-- Attempting to link static binaries...
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/istvan/source/orig/tigervnc/build

started the build with make, and it stops on linking vncconfig.exe:

[ 55%] Building CXX object win/rfb_win32/CMakeFiles/rfb_win32.dir/WMWindowCopyRect.cxx.obj
[ 56%] Building CXX object win/rfb_win32/CMakeFiles/rfb_win32.dir/CleanDesktop.cxx.obj
[ 56%] Linking CXX static library librfb_win32.a
[ 56%] Built target rfb_win32
Scanning dependencies of target vncconfig
[ 57%] Building CXX object win/vncconfig/CMakeFiles/vncconfig.dir/Legacy.cxx.obj
[ 57%] Building CXX object win/vncconfig/CMakeFiles/vncconfig.dir/PasswordDialog.cxx.obj
[ 58%] Building CXX object win/vncconfig/CMakeFiles/vncconfig.dir/vncconfig.cxx.obj
[ 58%] Building RC object win/vncconfig/CMakeFiles/vncconfig.dir/vncconfig.rc.obj
[ 59%] Linking CXX executable vncconfig.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(system.o):(.text+0x6): undefined reference to `clock_gettime'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0xb9): undefined reference to `idn2_to_ascii_8z'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0xe3): undefined reference to `idn2_free'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0x10f): undefined reference to `idn2_free'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0x20f): undefined reference to `idn2_to_ascii_8z'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0x247): undefined reference to `idn2_strerror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0x276): undefined reference to `idn2_strerror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0x3b0): undefined reference to `idn2_to_unicode_8z8z'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0x3fa): undefined reference to `idn2_free'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.text+0x4ad): undefined reference to `idn2_strerror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(str-idna.o):(.rdata$.refptr.idn2_free[.refptr.idn2_free]+0x0): undefined reference to `idn2_free'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(pkcs11.o):(.text+0x14c): undefined reference to `p11_kit_module_get_flags'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(pkcs11.o):(.text+0x27a): undefined reference to `p11_kit_modules_load_and_initialize'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib\libgnutls.a(pkcs11.o):(.text+0x2cd): undefined reference to `p11_kit_module_get_name'
...

what i have done is nothing more than just added the libraries related to the missing references (without any deeper analysis of the cause of the problem) in order to completely build the semi-static binaries without any errors.

if you need any more files, logs, etc. just tell me, i try to include.

@CendioOssman
Copy link
Member

Seems to be several issues here, so let's try to get one sorted at a time.

For GnuTLS it seems that idn2 and p11-kit are optional dependencies. We would need to detect that at build time somehow. Most likely the same approach as we do for nettle and such.

Could you test this patch:

diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake
index 97cfcb27..ebb23678 100644
--- a/cmake/StaticBuild.cmake
+++ b/cmake/StaticBuild.cmake
@@ -38,6 +38,12 @@ if(BUILD_STATIC)
     FIND_LIBRARY(TASN1_LIBRARY NAMES tasn1 libtasn1
       HINTS ${PC_GNUTLS_LIBDIR} ${PC_GNUTLS_LIBRARY_DIRS})
 
+    # And a bunch of optional dependencies
+    FIND_LIBRARY(IDN2_LIBRARY NAMES idn2 libidn2
+      HINTS ${PC_GNUTLS_LIBDIR} ${PC_GNUTLS_LIBRARY_DIRS})
+    FIND_LIBRARY(P11KIT_LIBRARY NAMES p11-kit libp11-kit
+      HINTS ${PC_GNUTLS_LIBDIR} ${PC_GNUTLS_LIBRARY_DIRS})
+
     set(GNUTLS_LIBRARIES "-Wl,-Bstatic -lgnutls")
 
     if(TASN1_LIBRARY)
@@ -49,6 +55,12 @@ if(BUILD_STATIC)
     if(GCRYPT_LIBRARY)
       set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lgcrypt -lgpg-error")
     endif()
+    if(IDN2_LIBRARY)
+      set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lidn2")
+    endif()
+    if(P11KIT_LIBRARY)
+      set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lp11-kit")
+    endif()
 
     set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -Wl,-Bdynamic")
 

The build probably won't succeed, but let's see how the errors progress.

@CendioOssman
Copy link
Member

#1039 has now been merged, so this should hopefully be fixed via that PR.

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

Successfully merging this pull request may close these issues.

3 participants