sourcey / libsourcey

C++14 evented IO libraries for high performance networking and media based applications
https://sourcey.com/libsourcey
GNU Lesser General Public License v2.1
1.32k stars 349 forks source link

"Undefined symbols for architecture x86_64" on MAC OS #78

Closed hoang21 closed 8 years ago

hoang21 commented 9 years ago

Hi, I got failed compiling (linking) libsourcey regarding "Undefined symbols for architecture x86_64".

Linking C shared library libminizip.dylib Building C object deps/libuv/CMakeFiles/libuv.dir/src/unix/getaddrinfo.c.o ld: warning: directory not found for option '-L/home/deploy/build/lib' Undefined symbols for architecture x86_64: "_crc32", referenced from: _unzReadCurrentFile in unzip.c.o _zipWriteInFileInZip in zip.c.o ....

Could you give any guide for me to fix it? Thanks.

Notes: I was following instruction from LibSourcey as following git clone https://github.com/sourcey/libsourcey.git cd libsourcey mkdir -p build && cd build cmake .. -DCMAKE_BUILD_TYPE=RELEASE # extra cmake commands here... make (Note that I got other issue with missing -lrt, which was fixed by removing dependency on lrt).

ZelimDamian commented 8 years ago

This is still an issue. OSX 10.11.1.

Error:

 [ 35%] Linking C shared library libminizip.dylib
ld: warning: directory not found for option '-L/home/deploy/build/lib'
Undefined symbols for architecture x86_64:
  "_crc32", referenced from:
      _unzReadCurrentFile in unzip.c.o
      _zipWriteInFileInZip in zip.c.o
  "_deflate", referenced from:
      _zipWriteInFileInZip in zip.c.o

Issue is apparently from missing link to zlib. Due to not knowing what exactly depends on what I changed the following in the define_sourcey_module macro:

  target_link_libraries(${name} ${LibSourcey_INCLUDE_LIBRARIES} zlib zlibstatic)

Didn't help unfortunately.

Thanks

ZelimDamian commented 8 years ago

I was able to overcome the missing lib link. (There are many other issues though)

I noticed that deps/zlib/CMakeLists.txt doesn't call define_sourcey_dependency. I didn't risk adding it in, but manually added some of what it does into it. Also had to alter some bits in the function itself:

diff --git a/cmake/LibSourceyDependency.cmake b/cmake/LibSourceyDependency.cmake
index d570842..504352c 100644
--- a/cmake/LibSourceyDependency.cmake
+++ b/cmake/LibSourceyDependency.cmake
@@ -36,10 +36,20 @@ macro(define_sourcey_dependency name)
   source_group("Include" FILES ${${name}_HEADER_FILES})

   add_library(${name} ${LibSourcey_LIB_TYPE} ${${name}_SOURCE_FILES} ${${name}_HEADER_FILES})
-  
-  if (${name}_DEPENDENCIES)
-    add_dependencies(${name} ${${name}_DEPENDENCIES})
-  endif()
+
+  # Include modules libraries first for the benefit of compilers
+  # which require ordered link libraries.
+  foreach(dep ${ARGN})
+    set(${name}_DEPENDENCIES ${${name}_DEPENDENCIES} ${dep})
+    add_dependencies(${name} ${dep})
+  endforeach()
+
+#   Add external dependencies and required libraries for linking.
+  target_link_libraries(${name} ${${name}_DEPENDENCIES})
+
+#  if (${name}_DEPENDENCIES)
+#    add_dependencies(${name} ${${name}_DEPENDENCIES})
+#  endif()

   # Include current directory and existing dependency directories
   include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${LibSourcey_INCLUDE_DIRS}")
@@ -102,9 +112,3 @@ endmacro()
     #  add_executable(${name} ${${name}_SOURCE_FILES} ${${name}_HEADER_FILES})
     #endif()

-    # Include modules libraries first for the benefit of compilers
-    # which require ordered link libraries.
-    #foreach(module ${ARGN})
-    #  include_sourcey_modules(${module})  
-    #  add_dependencies(${name} ${module})
-    #endforeach()
\ No newline at end of file
diff --git a/deps/minizip/CMakeLists.txt b/deps/minizip/CMakeLists.txt
index 75dbee3..6d7c73d 100644
--- a/deps/minizip/CMakeLists.txt
+++ b/deps/minizip/CMakeLists.txt
@@ -21,4 +21,4 @@ endif()

 # iowin32.h iowin32.c

-define_sourcey_dependency(minizip)
\ No newline at end of file
+define_sourcey_dependency(minizip zlib)
\ No newline at end of file
diff --git a/deps/zlib/CMakeLists.txt b/deps/zlib/CMakeLists.txt
index 4bd3fb5..b414034 100644
--- a/deps/zlib/CMakeLists.txt
+++ b/deps/zlib/CMakeLists.txt
@@ -245,6 +245,14 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
     install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
 endif()

+# Include current directory and existing dependency directories
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${LibSourcey_INCLUDE_DIRS}")
+
+# Cache dependency directories for inclusion by modules and applications
+get_directory_property(lib_directories INCLUDE_DIRECTORIES)
+set(LibSourcey_INCLUDE_DIRS ${lib_directories} PARENT_SCOPE)
+set(LibSourcey_INCLUDE_LIBRARIES ${LibSourcey_INCLUDE_LIBRARIES} ${name} PARENT_SCOPE)
+
 #============================================================================
 # Example binaries
 #============================================================================
auscaster commented 8 years ago

Please sync with the latest source code, I think this issue has been fixed.