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

ZLib Linking error #19

Open
sromer opened this issue Oct 24, 2016 · 12 comments
Open

ZLib Linking error #19

sromer opened this issue Oct 24, 2016 · 12 comments

Comments

@sromer
Copy link

sromer commented Oct 24, 2016

Hi,

I am currently trying to build the FIFEngine tutorial, but I am getting stuck at the following error:

sromer@ubuntu:~/Development/cpp-tutorials/src/_build$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Set CMAKE_BUILD_TYPE to default 'Release'.

== Building fife-cpp-tutorials using build type 'Release'.
--     Source directory is '/home/sromer/Development/cpp-tutorials/src'.
--     Build  directory is '/home/sromer/Development/cpp-tutorials/src/_build'.
--     Installation path is '/usr/local' (set -DCMAKE_INSTALL_PREFIX=<path> to change).
--     CXX Compiler Flags: ''.
--     Dependencies folder: '/home/sromer/Development/cpp-tutorials/src/../dependencies'.

-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Found FIFE: /usr/local/lib/libfife.a (found version "0.4.0") 
-- Found the following FifeChan libraries:
--   fifechan_opengl
--   fifechan_sdl
-- Found FIFECHAN: /usr/local/lib/libfifechan.so   
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   system
--   filesystem
--   regex
-- Found VORBIS: /usr/lib/x86_64-linux-gnu/libvorbisfile.so  
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8") 
-- Found PNG: /usr/lib/x86_64-linux-gnu/libpng.so (found version "1.2.54") 
-- Found OGG: /usr/lib/x86_64-linux-gnu/libogg.so  
<FindSDL2.cmake>
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
</FindSDL2.cmake>
-- Found SDL2: /usr/lib/x86_64-linux-gnu/libSDL2main.a;/usr/lib/x86_64-linux-gnu/libSDL2.so;-lpthread  
-- Found SDL2_image: /usr/lib/x86_64-linux-gnu/libSDL2_image.so (found version "2.0.1") 
-- Found SDL2_ttf: /usr/lib/x86_64-linux-gnu/libSDL2_ttf.so (found version "2.0.14") 
-- Found OpenAL: /usr/lib/x86_64-linux-gnu/libopenal.so  
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so  
-- Found TinyXML: /usr/lib/x86_64-linux-gnu/libtinyxml.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sromer/Development/cpp-tutorials/src/_build
sromer@ubuntu:~/Development/cpp-tutorials/src/_build$ make
Scanning dependencies of target Tutorial1
[ 14%] Building CXX object tutorial_1/CMakeFiles/Tutorial1.dir/MouseListener.cpp.o
[ 28%] Building CXX object tutorial_1/CMakeFiles/Tutorial1.dir/ScreenScroller.cpp.o
[ 42%] Building CXX object tutorial_1/CMakeFiles/Tutorial1.dir/Game.cpp.o
[ 57%] Building CXX object tutorial_1/CMakeFiles/Tutorial1.dir/main.cpp.o
[ 71%] Building CXX object tutorial_1/CMakeFiles/Tutorial1.dir/KeyListener.cpp.o
[ 85%] Building CXX object tutorial_1/CMakeFiles/Tutorial1.dir/ViewController.cpp.o
[100%] Linking CXX executable Tutorial1
/usr/bin/ld: /usr/local/lib/libfife.a(zipsource.cpp.o): undefined reference to symbol 'inflateInit2_'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libz.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
tutorial_1/CMakeFiles/Tutorial1.dir/build.make:268: recipe for target 'tutorial_1/Tutorial1' failed
make[2]: *** [tutorial_1/Tutorial1] Error 1
CMakeFiles/Makefile2:85: recipe for target 'tutorial_1/CMakeFiles/Tutorial1.dir/all' failed
make[1]: *** [tutorial_1/CMakeFiles/Tutorial1.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

I figured libz.so might be missing from my system, but as you can see, CMake is able to find the libz library correctly: Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8"). I have checked if the library is indeed installed and can be found/accessed at the folder in which CMake locates libz and that is the case.

I am running Ubuntu 16.04 LTS (x64).

Hopefully someone can help me out!

@LinuxDonald
Copy link

Give it an libz devel package maybe?

@sromer
Copy link
Author

sromer commented Oct 24, 2016

Wow @LinuxDonald you are fast!

The following libs are installed:

ii  zlib1g:amd64      1:1.2.8.dfsg-2ubuntu4  amd64   compression library - runtime
ii  zlib1g:i386       1:1.2.8.dfsg-2ubuntu4  i386    compression library - runtime
ii  zlib1g-dbg        1:1.2.8.dfsg-2ubuntu4  amd64   compression library - development
ii  zlib1g-dev:amd64  1:1.2.8.dfsg-2ubuntu4  amd64   compression library - development
ii  zlib1g-dev:i386   1:1.2.8.dfsg-2ubuntu4  i386    compression library - development

@LinuxDonald
Copy link

i will take an look later on it. I have tested it last time on ArchLinux and dont had any problems. But i have Ubuntu installed too i will test it and see what happens.

@sromer
Copy link
Author

sromer commented Oct 24, 2016

Just tested it on a clean Kubuntu install, because @milandamen has no problems with building on Kubuntu, but I am getting the same (undefined reference to symbol 'inflateInit2_') error as well. Don't have an ArchLinux install at the moment...

@LinuxDonald
Copy link

Have you installed all fife deps? https://github.com/fifengine/fifengine/wiki/Compiling-fife

@sromer
Copy link
Author

sromer commented Oct 28, 2016

Yes, all deps have been installed properly.

@jakoch
Copy link
Member

jakoch commented Oct 28, 2016

We have find_package, include and finally target_link_directory for zlib on tutorial_1.
zlib is also on position 1 in the linking order, so that it's symbols "should be available" for following objects. Travis is also green for Linux.

Do you have any errors messages during building libfife?

@sromer
Copy link
Author

sromer commented Oct 28, 2016

Just cloned the fifengine repo and build from source. Have not seen any errors during the build process, also the installed ZLib library (1.2.8) is found.

cmake -> http://pastebin.com/McLVqHN4
make -> http://pastebin.com/nMsscz6r
make install -> http://pastebin.com/AZMttVBM

@jakoch
Copy link
Member

jakoch commented Oct 28, 2016

Thank you for posting the logs.
According to the logs everything is fine: no compilation errors, nor errors regarding zlib.
All looking good.

What could help is to go into cmake verbose mode to see the linker commands.
Running make VERBOSE=1 should output more information.
If i would do the linking manually, i would use -lz.
But let's see what cmake does. It could be a library prefix or a path issue.

Another thing, which could help is, to output the vars from the library detection done by find_package(zlib). We need to check, if we get the correct values for ${ZLIB_INCLUDE_DIR} and especially ${ZLIB_LIBRARIES}.

Just add the following lines after find_package did it's job and the vars have been set.
Here:

message("==> ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIR}")
message("==> ZLIB_LIBRARIES ${ZLIB_LIBRARIES}")

@sromer
Copy link
Author

sromer commented Oct 28, 2016

I have ran make with VERBOSE=1
Output: http://pastebin.com/yvwy0Naf

Also when adding the message statements to the cmake file I get the following output
==> ZLIB_INCLUDE_DIR /usr/include ==> ZLIB_LIBRARIES /usr/lib/x86_64-linux-gnu/libz.so

Which seem like the legit folders...

@jakoch
Copy link
Member

jakoch commented Oct 29, 2016

Thank you. The message output is ok. libz.so is what we want to link.

The verbose output is for fifengine itself - and i noticed one issue, regarding Fifechan:

  • -I/home/stephanromer/Development/fifengine/FIFECHAN_INCLUDE_DIR-NOTFOUND/fifechan

Seems the includes for fifechan are missing or not detected properly.
Referencing: fifengine/fifengine#938

The later maybe, because the old logs show that the lib is found Found FIFECHAN: /usr/local/lib/libfifechan.so.
I wonder, why this issue doesn't bubble up as an error in non-verbose mode.


Update: i've enabled verbose mode on Travis for Linux builds.

I could reproduce the Fifechan include issue

But not the original zlib linking issue (the linker line contains -lz).

jakoch added a commit that referenced this issue Oct 29, 2016
@milandamen
Copy link
Contributor

milandamen commented Oct 31, 2016

I recreated the exact problem in a VM running Ubuntu 64bit and I found a solution:

Instead of running cmake .. -Dbuild-library:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF on fifengine, you should run cmake .. -Dbuild-library:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON.

That's it. The tutorial builds correctly now. It doesn't fix the original issue but it can be used as a workaround for the time being.

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

4 participants