Undefined reference to 'inflateInit2_' - c++

I'm using Code Blocks IDE and I want to install Tiled Map Editor for SFML. So, I downloaded the source and imported it to my project. Unfortunately, the build finished with an error due to missing zlib library. I downloaded it and built again. This time I received an error that reads:
undefined reference to `inflateInit2_'|
undefined reference to `inflateEnd'|
undefined reference to `inflateEnd'|
On the Internet I found the advice to join the linker command -lz, but the compiler refuses throwing the error: cannot find -lz. Does anyone know how to fix it?

Use the option -L<path> to tell the linker where to find libz.so.x.y.z.
For your reference: http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

you can see where your zlib is installed like this :
/sbin/ldconfig -p| grep libz.so
it should find one or more entries if installed, otherwise it will return blank line

Related

RcppGSL Windows installation trouble

I'm trying to install RcppGSL as presented in
Linking GSL library to RcppGSL on Windows machine
after copping the library as presented in the link above to C:/local323
and moving all the files in x64 up one directory into into LIB_GSL/lib as presented in the link. I used the following code.
library(Rcpp)
Sys.setenv("LIB_GSL" = "C:/local323") # this is where the library is located
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
install.packages("RcppGSL")
I added the line
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
after getting the following error(and I still got the same error) after doing some research and thought there might be a linking problem(just guessing).
The error I received was
RcppExports.o:RcppExports.cpp:(.text+0x916): undefined reference to `gsl_matrix_alloc'
RcppExports.o:RcppExports.cpp:(.text+0x945): undefined reference to `gsl_matrix_set'
RcppExports.o:RcppExports.cpp:(.text+0x993): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x122): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x131): undefined reference to `gsl_matrix_alloc'
fastLm.o:fastLm.cpp:(.text+0x142): undefined reference to `gsl_multifit_linear_alloc'
fastLm.o:fastLm.cpp:(.text+0x16d): undefined reference to `gsl_multifit_linear'
fastLm.o:fastLm.cpp:(.text+0x175): undefined reference to `gsl_multifit_linear_free'
fastLm.o:fastLm.cpp:(.text+0x24f): undefined reference to `gsl_matrix_diagonal'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x104): undefined reference to `gsl_set_error_handler_off'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x133): undefined reference to `gsl_set_error_handler'
any help is greatly appreciated!
Very best,
Steve
I would try this on the command-line, ie in cmd.exe -- not from R.
That way you should see the compilation and linking steps which may help when something go south.
"It builds at CRAN ..." so with the right files in the right location, and the proper env var set it should for you too.
Well I do not know why the following worked but I'm able to use RcppGSL
I followed the procedure from the link I posted exactly. Then instead of using
install.packages("RcppGSL")
I downloaded the zip file from CRAN and installed the package via the R GUI with the option to install from a zip. These should be identical I know, but using install.packages("RcppGSL").
Also
Sys.setenv("LIB_GSL" = "C:/local323")
is required anytime I try to compile an Rcpp file that uses the library.
I'm not sure why, but I can use the library at least.
Dirk thank you for your help. I will go over the tutorial on R-extensions to see if I can figure out what is going on.

Linking Intel's MKL (BLAS & LAPACK) to GCC

I am trying to compile a giant software package, and this is the last hurdle I can't seem to figure out.
I'm getting errors like:
RNDiracDeterminantBase.cpp:(.text+0x22bf): undefined reference to `dgetrf_'
RNDiracDeterminantBase.cpp:(.text+0x2524): undefined reference to `dgetri_'
RNDiracDeterminantBase.cpp:(.text+0x3005): undefined reference to `dgetri_'
../../lib/libqmcwfs.a(RNDiracDeterminantBase.cpp.o): In function `qmcplusplus::RNDiracDeterminantBase::ratio(qmcplusplus::ParticleSet&, int, qmcplusplus::ParticleAttrib<qmcplusplus::TinyVector<double, 3u> >&, qmcplusplus::ParticleAttrib<double>&)':
RNDiracDeterminantBase.cpp:(.text+0x4156): undefined reference to `dgemv_'
RNDiracDeterminantBase.cpp:(.text+0x420f): undefined reference to `dger_'
Google reveals that these references are to Intel's MKL library. However, I don't know what file I need to link. I've tried libmkl_core.a, libmkl_gnu_thread.a, libmkl_blacs_intelmpi_lp64.a, etc. There's tons of files in:
/mkl/lib/intel64/
Can post more information if requested.
I don't know what file I need to link. I've tried libmkl_core.a, libmkl_gnu_thread.a, libmkl_blacs_intelmpi_lp64.a, etc. There's tons of files in: /mkl/lib/intel64/
The fact that there are tons of files doesn't mean you have to try each library in turn.
To find out which library defines the symbols you want, run this command:
cd /mkl/lib/intel64
nm -A *.a | egrep '[TWBD] (dger_|dgemv_|dgetrf_|dgetri_)$'
Also be sure to put libraries at the end of your link line, as the order of archive libraries on command line matters.
Based on the incomplete information you provided, it's likely that you need libmkl_intel_lp64.a, libmkl_gnu_thread.a, and libmkl_core.a.
Intel MKL has a built-in tool to help you figure out linking: /mkl/tools/mkl_link_tool. This tool is also available on the web: http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor. Use this tool to get the exact link line for your situation.
You should have asked your question on the official MKL forum (http://software.intel.com/en-us/forums/intel-math-kernel-library). You'd get the answer for this type of questions within hours instead of days.
I had a similar problem when setting up mingw on windows.
The following library linking order worked for me with gcc:
mkl_intel_thread
mkl_rt
mkl_core
mkl_intel_lp64
Hope this helps anyone stuck with this problem.

trying to use the basic tutorial for ogre in code::blocks produces undefined references to '__unwind_resume' and '__gxx_personality_v0'

When following this tutorial I'm getting the following errors: undefined reference to '__unwind_resume' and undefined reference to '__gxx_personality_v0'
The file producing these undefined reference error's is libboost_system-mgw47-mt-1_51.a. I have already tried the following fixes to no avail:
Forcing Code::blocks to use g++ instead of gcc.
Result: No change
Adding-lstdc++ to the list of libraries the linker links to.
Result: 39 more errors in addition to the __unwind_resume and __gxx_personality_v0 undefined reference errors.
Installing the latest MingW and pointing my compiler to use it instead of its own version
Result: Compiler errors now exceeds max value :(
image2 http://s24.postimage.org/3u6tik4dh/moreerrors2.jpg
Any help troubleshooting these errors is appreciated, I really want to get this thing working.
I found part of the solution, I got the compiler to create an executable file, but it currently throws OGRE::filenotfoundexception and terminates. I did this by downloading boost_1_53_0 and building libboost_system-mgw47-mt-1-53.a and linking to that instead of the other one, then it gave me the error on startup "the procedure entry point __gxx_personality_v0 could not be located in the dynamic link library libstdc++-6.dll." So to work around that I went to orwell's mingw folder and found that libstdc++-6.dll in that folder was around 800 KB in size and the one codeblocks was using was 5 mb, I switched them out to see if it worked and it got the executable running now but it throws said exception and terminates.
EDIT1: Strangely enough simply adding a blank file called resources.cfg (the file that caused the exception) causes the program to run but now an Ogre windows appears asking for a rendering system
EDIT2: After realizing I'm supposed to copy everything from ogre's bin/release directory to my executable files directory (and the media directory to 2 folders up from my executables directory) I did that and everything finally worked perfectly!

Libusb undefined reference to

I'm trying to set up libusb API on my OS. I downloaded libusb api on libusb.org. I followed the standard installation procedure:
cd into directory
./configure
make
make check //without errors
make install
Then I launched Eclipse C/C++ and copied some code from the tutorial found on the internet. But when trying to build it I got following output:
main.cpp:(.text+0x19): undefined reference to `libusb_init'
main.cpp:(.text+0x76): undefined reference to `libusb_set_debug'
main.cpp:(.text+0x8a): undefined reference to `libusb_get_device_list'
main.cpp:(.text+0x136): undefined reference to `libusb_free_device_list'
main.cpp:(.text+0x142): undefined reference to `libusb_exit'
/tmp/ccOWJGwe.o: In function `printdev(libusb_device*)':
main.cpp:(.text+0x162): undefined reference to `libusb_get_device_descriptor'
main.cpp:(.text+0x28a): undefined reference to `libusb_get_config_descriptor'
main.cpp:(.text+0x4d4): undefined reference to `libusb_free_config_descriptor'
collect2: ld returned 1 exit status
I have libusb.so in /lib and also I have usb.h in /usr/local/include and the link for the .so and libusb.a in /usr/local/lib.
Also the #include inside the code is correct.
I know that problem is in linker but I, kind of, cannot make it work :)
I'm using Fedora 15 operating system and gcc 4.6.0 20110603 (Red Hat 4.6.0-10) version compiler.
So what could I do to resolve these undefined references? Thanks very much for help :)
I did face the same problem. But I was able to solve it by adding '-lusb-1.0' to the linker.
e.g : g++ myfile.cpp -lusb-1.0
you have to set the library linker flag for compilation in the linker,
you can get a full list in the console by executing
pkg-config --list-all
These are the libraries which you have installed on your system and you have to link against the ones you want to use.
so in your example it is libusb so you do
pkg-config --libs libusb
there should be the output
-lusb
or
-lusb-1.0
This gives you the flag you have to pass to the linker. e.g.
g++ myfile.cpp -lusb[-1.0]
Then you edit the configuration of the project and search for the linkerflags, there should be a textfield for that somewhere in the buildoptions. i'm not quite shure where to find it but googling for it suggested:
Project -> Properties -> C/C++
Build -> Miscellaneous -> flags
After you found it, just add the linker flag in the textfield and you should be fine.
EDIT
since my answer is the accepted one, I also added the other flag that seems to work for a lot of people.
What is your linker command line? You need to have -lusb in the linking command; just having the header included won't work.
I don't use Eclipse C/C++ but I am pretty sure the reason is the same that I faced some while ago when setting up a C project in Netbeans.
It's not enough to have the #include in your code and the library at the right location - you also have to tell Eclipse where to look for them and how to use them. This turorial shows you how to set it up in Eclipse.

Link error: undefined reference to EVP_CIPHER_CTX_ and EVP_CIPHER_CTX_init

I am using crypto++ in my code. I don't want to use its dependencies so i've tried to import crypto++ files in my folder and include them in my .cpp file
I have the followng errors:
TEST.cpp:(.text+0x89a0): undefined reference to `EVP_CIPHER_CTX_init'
TEST.cpp:(.text+0x8cb0): undefined reference to `EVP_aes_128_cbc'
TEST.cpp:(.text+0x8cdd): undefined reference to `EVP_CipherInit_ex'
TEST.cpp:(.text+0x8d49): undefined reference to `EVP_CipherUpdate'
TEST.cpp:(.text+0x8dd6): undefined reference to `EVP_CipherFinal_ex'
TEST.cpp:(.text+0x922d): undefined reference to `EVP_CIPHER_CTX_cleanup'
what am i missing? need some help. Appreciate!
I am working in ubuntu.
You need to do two things, of which you've only done one so far.
You need to tell your compiler where to find the appropriate declarations. You've done this by adding
#include "evp.h"
in your source file. (Depending on how you installed crypto++, you might also need to tell the compiler where to find "evp.h", probably using -Isome_directory.)
The step you're missing is telling the linker where to find the actual implementation (the compiled code) of the functions you're using. According to the Readme.txt file included in the distribution, bulding crypto++ creates a library file called libcryptopp.a.
So something like this should do the job:
gcc my_program.c -o my_program -lcryptopp
Depending on how and where you installed it, you might also need to specify -Lsome_directory to tell the linker where to find libcryptopp.a. (The gcc command invokes both the compiler and the linker. The -l option tells the linker to use libcryptopp.a. The -L option, if needed, tells it what directory to look in.)
TEST.cpp:(.text+0x89a0): undefined reference to `EVP_CIPHER_CTX_init'
TEST.cpp:(.text+0x8cb0): undefined reference to `EVP_aes_128_cbc'
TEST.cpp:(.text+0x8cdd): undefined reference to `EVP_CipherInit_ex'
TEST.cpp:(.text+0x8d49): undefined reference to `EVP_CipherUpdate'
TEST.cpp:(.text+0x8dd6): undefined reference to `EVP_CipherFinal_ex'
TEST.cpp:(.text+0x922d): undefined reference to `EVP_CIPHER_CTX_cleanup'
That's not Crypto++ - its OpenSSL.
If you need to install Crypto++ on Ubuntu, then:
root#bruno:/# apt-cache pkgnames | grep -i crypto++
libcrypto++-utils
libcrypto++8
libcrypto++8-dbg
libcrypto++-dev
libcrypto++-doc
root#bruno:/# apt-get install libcrypto++8 libcrypto++8-dbg libcrypto++-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libcrypto++-dev libcrypto++8 libcrypto++8-dbg
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 10.7MB of archives.
...