Zlib linking problems - c++

I'm using CodeBlocks (the latest version, I'm not sure what that is at the moment)
I'm trying to use fallahn's SFML Tiled map loader, and so far I've successfully statically linked SFML and included the map loader files in my source as well as added it to my search directories, however, I'm having trouble linking zlib (which the map loader uses)
I'm gonna go ahead and walk you through how I linked zlib because I'm not even sure which step I messed up on:
obviously, I went on over to http://zlib.net and grabbed the latest version (1.2.8)
I unzipped it to my desktop
I went into my project's build options and initially i thought "I'll just globally set up my search directories like before" (for SFML and the map loader, there was an 'include' and 'lib' folder, i put 'include' in the compiler search directory, and 'lib' in the linker search directory), except there were no folders named 'include' or 'lib' in the folder that i got from unzipping. This is where I simply included the whole folder I unzipped (I'm pretty sure that's terrible practice but I wasn't sure what else to do)
I compiled an example from the Map loader's source files, and got an error along the lines of 'undefined reference to inflate' on 4 different occasions. I already figured at this point that I made an error while linking, so that's when I took to google. Most answers were simply "add -lz" or "link libz"
Well, I don't know what "add -lz" means.. like at all, so I just linked "libz", then my compiler gave me the error "ld.exe cannot find -lz", which led me to the assumption that linking libz and adding -lz are the same thing.
Here are some things I don't understand at all, and if you can't explain what they are, please at least explain how to blindly do it:
1. Compiling a library
2. Anything to do with make files, I don't know what they are or what they do at all
3. Adding commands to the project command-line.
Build messages:
C:/Documents and Settings/Brenda/Desktop/sfml-tmxloader-master/src/MapLoaderPrivate.cpp:834: undefined reference to inflateInit2_'
C:/Documents and Settings/Brenda/Desktop/sfml-tmxloader-master/src/MapLoaderPrivate.cpp:843: undefined reference toinflate'
C:/Documents and Settings/Brenda/Desktop/sfml-tmxloader-master/src/MapLoaderPrivate.cpp:852: undefined reference to inflateEnd'
C:/Documents and Settings/Brenda/Desktop/sfml-tmxloader-master/src/MapLoaderPrivate.cpp:881: undefined reference toinflateEnd'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 10 seconds)
4 errors, 0 warnings (0 minutes, 10 seconds)

The issue is, that zlib doesn't provide binaries for MinGW directly, they only provide *.lib, *.def and *.dll files, but in order to link with MinGW/GCC, you'll need an *.a file.
Since zlib is a C library the ABI will be identical and thus you can "simply" convert it, for instance with the help of lib2a. While this should work, it might still be better to download the source code and build zlib yourself, since it ships with a CMake file, it's rather easy to build.

Related

Why does my linker search for Coin4sd.lib after it found Coin4d.lib?

I am using the Coin 4.0.0 library (https://github.com/coin3d/coin) for a certain project. When building that library using CMake, I get amongst others the following files:
bin
|-- Coin4d.dll
`-- Coin4d.pdb
lib
|-- Coin4d.lib
Which looks fine to me. Then, we are using qmake to build our final executable. In my qmake .pro file I have
LIBS += -lCoin4d
However, when the final .exe is linked together using the Visual Studio 2015 linker, then I see that it first searches for (and finds) Coin4d.lib:
Searching D:/SVN/simcad/trunkd/ThirdParty/Coin/install/lib\Coin4d.lib:
However, a bit later, I get the linker error
LINK : fatal error LNK1104: cannot open file 'Coin4sd.lib'
Mind the extra 's' in the library file name here!
I have no idea why the linker is also looking for Coin4sd.lib after it found Coin4d.lib. I would like to systematically find this out, but don't know where to start.
So my question is: what tools/commands can I use to systematically find out why my linker is also searching for Coin4sd.lib after it apparently first found Coin4d.lib? Should I investigate the libraries that are used to build the final executable too, and check if any of those somehow refer to Coin4sd.lib?
I found out that I was using COIN_DLL as define, which apparently caused me to have the Coin4d.* filenames. When I use COIN_NOT_DLL then if I understand things correctly, the static version of the library (which has filename Coin4sd.*) gets built and then my linker no longer complains.

Need help understanding C++ libraries, compiling, linking, header files for specific project

This is my first stab at C++, also I know that the question is broad but I have a specific example that I'm working with so hopefully that will narrow everything down a bit.
I'm basically attempting to compile a C++ game manually in Linux (Ubuntu 14.04). The source code I am attempting to compile is located in this directory: https://github.com/akadmc/SmashBattle/tree/master/battle.
I'm CD'ing into the battle directory and, perhaps naively running
gcc *.cpp
I started seeing multiple issues as such:
compilation terminated.HealthPowerUp.cpp:1:21:
fatal error: SDL/SDL.h: No such file or directory #include "SDL/SDL.h"
and
compilation terminated.LaserBeamPowerUp.cpp:1:21:
fatal error: SDL/SDL.h: No such file or directory #include <SDL/SDL.h>
After researching header file includes I concluded that includes without <>'s are basically just relative paths to include a header file, and that when they are wrapped in <>'s they can either lookup the file through a listing of directories specified in an enviornment variable, or a command line option.
So my first question is, is there any reason the developer used
#include "SDL/SDL.h
AND
#include <SDL/SDL.h>
in different files? There was no SDL directory in the source code...
After realizing that SDL was missing from the source code / environment in one way or another I did tinkering. I was pretty confused (and still am) because I downloaded the SDL source files, didn't see any header files, ended up building a version of SDL by using cmake, and then build. I realized afterwards that I just made a local executable and didn't yield any header files. Then I realized that I just needed the development library, downloaded that, and put higher in the directory tree and then included it at compile with
c++ *.cpp -I $HOME/Desktop/smashProject/source/
Afterwards, the previous header file errors went away - but I started getting errors like the following:
Text.cpp:(.text+0x17): undefined reference to `SDL_RWFromFile'
Text.cpp:(.text+0x24): undefined reference to `SDL_LoadBMP_RW'
Text.cpp:(.text+0x34): undefined reference to `SDL_DisplayFormat'
And so on. Am I generally headed in the right path or do I have some misunderstanding about compiling, including development libraries, etc? Also I've read the the order of the compilation matters, and I'm not using any order + the developer didn't put a makefile in the source code or anything. I'm generally just confused as to how I should be doing this. Any help would be greatly appreciated.
Yes, you are on the right track. However, now you need to have a linkage to the SDL libraries. The -I just includes an extra library path but you have to actually link your assembly to the SDL files.
See this stack overflow question for more information.
How to compile an example SDL program written in C?

How to find the missing dependency in failed compilation?

Sometimes when compiling the errors output the name of a header file that is missing, and the package it comes from can be tracked down using the Linux package manager.
But how to find the missing dependency when the error is of the sort below, where it doesn't give you the name of the missing header file?
make[2]: *** [examples/undocumented/libshogun/base_map_parameters] Error 1
CMakeFiles/Makefile2:916: recipe for target 'examples/undocumented/libshogun/CMakeFiles/base_map_parameters.dir/all' failed
make[1]: *** [examples/undocumented/libshogun/CMakeFiles/base_map_parameters.dir/all] Error 2
../../../src/shogun/libshogun.so.17.1: undefined reference to `SZ_BufftoBuffDecompress'
../../../src/shogun/libshogun.so.17.1: undefined reference to `SZ_encoder_enabled'
../../../src/shogun/libshogun.so.17.1: undefined reference to `SZ_BufftoBuffCompress'
collect2: error: ld returned 1 exit status
examples/undocumented/libshogun/CMakeFiles/base_migration_dropping_and_new.dir/build.make:129: recipe for target 'examples/undocumented/libshogun/base_migration_dropping_and_new' failed
The header file example you present is a compile time error. The compiler knows about the files and can present you with what is missing. The error you are presenting above is a link time error.
The one you present is a common one and it is that a symbol is not defined. Usually this happens because a library was excluded from the linker line. Another common source of this error is that the library you are linking to is older than the one expected for the program.
Usually I find myself trolling Google for articles like this one when presented with such errors. The packaging manager does not track function level details when accounting for files or libraries. I always thought it would be nice enhancement to inspect libraries with the nm command and put that meta data into packaging systems.
(This is not a generic answer, but) In this case, googling SZ_BufftoBuffDecompress gave, among others, the link to https://github.com/PacificBiosciences/blasr/issues/4, where it is suggested
It seems that the hdf5 library is not correctly installed. The hdf5 lib that you used requires szip library. So you may need to install szip lib first and then re-make your hdf5 package (linking it with the szip lib, -lsz).
So it seems as though the missing dependency is szip.
As for general searching, #Thomas Padron-McCarthy's comment sensibly advises to
perhaps add the program name
and
on Ubuntu I might also add apt-get and install, to directly find instructions on how to install the missing parts!
If you only need the software, and do not feel the need to compile it yourself, have a look at the github post. Another poster
suggest[s] using Homebrew and Linuxbrew to install science software on Mac and Linux, repsectively[sic].

Android NDK:undefined reference to ' '

I am trying to build a library file of g729 codec.i have source of this codec and trying to build using Android NDK.Almost all object files are built but at last i am getting this error.
But i am stuck with this error. can anyone explain the meaning of this error and what should i do to solve this?
./obj/local/armeabi-v7a/objs/g729_jni/g729/cod_ld8a.o: In function `Coder_ld8a':
/root/g729/jni/g729/cod_ld8a.c:267: undefined reference to `Pitch_ol_fast'
/root/g729/jni/g729/cod_ld8a.c:325: undefined reference to `Pitch_fr3_fast'
/root/g729/jni/g729/cod_ld8a.c:328: undefined reference to `Enc_lag3'
/root/g729/jni/g729/cod_ld8a.c:344: undefined reference to `G_pitch'
collect2: ld returned 1 exit status
Thanks
Edit
I have solved this error but is it feasible?
I have added this line in Android.mk
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
If you are compiling the sources and you want to link the resulting library you can use one of the following variables in your Android.mk file
LOCAL_STATIC_LIBRARIES:
The list of static libraries modules (built with BUILD_STATIC_LIBRARY)
that should be linked to this module. This only makes sense in
shared library modules.
LOCAL_SHARED_LIBRARIES:
The list of shared libraries modules this module depends on at runtime.
This is necessary at link time and to embed the corresponding information
in the generated file.
For more details have a look at the android NDK documentation that you can find in the ndk folder.
Otherwise if you have to link a prebuilt library there is a section in the Android NDK documentation that tells you how to achieve the result. An on-line version of these documents is also here(PREBUILTS).
UPDATE 09/01/2017
Documentation about Prebuilt libraries can be found here

Using library files in Linux

I'm trying to use some of the functions that are in the /lib/libproc-3.2.6.so library in my Ubuntu distribution.
I have downloaded and installed the header files and they are defined in my source files.
Currently, this is all I'm trying to do, just for starters...
proc_t **read_proc = readproctab(0);
But I get the following compiler error:
/tmp/cclqMImG.o: In function `Sysmon::initialise_sysmon()':
sysmon.cpp:(.text+0x494): undefined reference to `readproctab'
collect2: ld returned 1 exit status
I'm aware I'm probably doing some wrong with the command I'm using to compile it, but due to lack of experience I'm not sure what I'm doing wrong. This is the g++ command I'm using to compile my cpp file:
g++ -o sysmon.o sysmon.cpp `pkg-config --libs --cflags gtk+-2.0`
Can someone please give me some pointers as to where I'm going wrong.
You are not linking your executable against libproc (that is a linker error message).
Try adding -lproc to the linker command.
You are not actually linking against the library that you wish to use, you are merely including its header files, therefor, the compiler will complain about undefined references.
You can read up on linking against shared libraries here.
A small suggestion, start using the build tool SCons, it can take care of linking to libraries for you, just add the ones you wish to use in the SConstruct file required by SCons and then you don't have to mess about with compiler specifics. You also gain lots of other good stuff that SCons provide. It's highly recommended.
Ubuntu 17.04
You probably want to use -lprocps instead of -lproc.