I installed openssl through binaries and i have that exact files at that exact location.
But when compiling i face this error. any idea?
g++ main.cpp -I /usr/local/openssl/include/openssl/
In file included from main.cpp:1:0:
main.h:4:25: fatal error: openssl/evp.h: No such file or directory
compilation terminated.
update:
the below command did the job but i still face errors.
g++ main.cpp -I/usr/local/openssl/include -L/usr/local/openssl/lib main.cpp -lcrypto
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x1d): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x33): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3d): undefined reference to `dlclose'
Any idea? :(
Solution :
g++ main.cpp -I/usr/local/openssl/include -L/usr/local/openssl/lib main.cpp -lcrypto -ldl
Change to:
g++ main.cpp -I /usr/local/openssl/include
as the include directive is including the name of the subdirectory.
Note you will have to add the openssl library to link with. I am not familiar with it but something like -lopenssl and add a directory to be searched to locate it using -L option. The full command would be something like (as I am guessing the lib directory and name of library for openssl):
g++ main.cpp -I/usr/local/openssl/include -L/usr/local/openssl/lib main.cpp -lopenssl
no space between -I and the path.
Related
I am compiling an opensource project to run on my machine which is this project. It requires boost library so I installed the Boost_1_55 library on my ubuntu machine but the compiling process was not successfully finished by printing out some error messages as follows.
libtool: link: g++ -g -O3 -Wall -DKENLM_MAX_ORDER=6 -W -Wall -Wno-sign-compare -I./.. -pthread -I/usr/include -g -O2 -o .libs/query query_main.o ./.libs/libklm.so ../util/.libs/libklm_util.so -lz -L/usr/lib/x86_64-linux-gnu -lboost_program_options -lboost_thread -lboost_system -lpthread -lrt -pthread
../util/.libs/libklm_util.so: undefined reference to `boost::thread::join()'
../util/.libs/libklm_util.so: undefined reference to `boost::thread::~thread()'
./.libs/libklm.so: undefined reference to `boost::thread::start_thread()'
collect2: ld returned 1 exit status
This answer seems the solution for my problem but the result of ls -al /usr/local/lib | grep thread showed me like below.
libboost_thread.a
libboost_thread.so -> libboost_thread.so.1.55.0
libboost_thread.so.1.49.0
libboost_thread.so.1.55.0
I don't know what else to check more. Thank you in advance for your help.
You can try to add /usr/local/lib to LD_LIBRARY_PATH like this
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
You have the static Boost library object (libboost_thread.so) but do you have the Boost development files installed? Check to see if the /usr/include/boost/thread directory exists and has *.hpp files in it. If not you may need to install the libboost-thread-dev package for your distribution or download the header files directly from Boost.org.
I'm busy trying to compile and link a c++ program using the following make file
driver.so:driver.cpp
g++ -c driver.cpp -o driver.so
g++ -L/tokenlib/libtokenlib.so driver.so -o linked
but I'm getting the error
g++ -c driver.cpp -o driver.so
g++ -L/tokenlib/libtokenlib.so driver.so -o linked
driver.so: In function `main':
driver.cpp:(.text+0x9): undefined reference to `tokenlib::acquire_token()'
collect2: error: ld returned 1 exit status
make: *** [driver.so] Error 1
and my file hierarchy is
/root
makefile
driver.cpp
/tokenlib
libtokenlib.so
I've been told that adding -Wl,-rpath=./tokenlib to my g++ arguements would solve the problem so I tried like this
driver.so:driver.cpp
g++ -c driver.cpp -o driver.so -Wl,-rpath=./tokenlib
g++ -L/tokenlib/libtokenlib.so driver.so -o linked -Wl,-rpath=./tokenlib
but it still isn't working.
I'm a complete novice and any help would be appreciated.
The linker usually refers to .a (stub) libraries, not to .so files!
-L options specify the paths, the lnker should take in account.
The -l<mystuff> option tries to resolve a library named libmystuff.a from any of the given path's of the -L options, or compiler intrinsic library search paths.
I have downloaded gtest 1.7.0 sources from here:
https://code.google.com/p/googletest/downloads/list
and build the gtest .a files (lib files) on ubuntu 13.10:
Linux ubuntu 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
and the resulting lib is called: libgtest.a. In my main.cpp file Have:
#include <iostream>
#include "gtest/gtest.h"
int main(){
std::cout << "Test \n";
int argc = 2;
char* cp01;
char* cp02;
char* argv[] = {cp01, cp02};
testing::InitGoogleTest(&argc, argv);
return 0;
}
From a terminal I build with:
g++ main.cpp -I/home/user/gtest-1.7.0/include -L/home/user/gtest-1.7.0/lib/.libs -lpthread -lgtest
which gives the following errors:
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_key_create'
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_getspecific'
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_key_delete'
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
Based on this:
error during making GTest
I have also tried -pthread instead of -lpthread but gives same error:
g++ main.cpp -I/home/user/gtest-1.7.0/include -L/home/user/gtest-1.7.0/lib/.libs -pthread -lgtest
EDIT: I have also tried to specifying -pthread as the last argument:
g++ main.cpp -I/home/user/gtest-1.7.0/include -L/home/user/gtest-1.7.0/lib/.libs -lgtest -pthread
same error
What am I doing wrong?
You need to specify -pthread after -lgtest. The linker takes libraries in order, and only takes as much as it needs to resolve references which are undefined at that point.
Nope, the problem is with Gtest's build.
If you build it using the standard configure approach, it isn't supplying the -lpthread correctly to create libgtest.so. Hence, when you try building a final shared library that actually uses the pthread capability it fails.
Instead, use the Cmake approach:
cd gtest-1.7.0
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make
And then manually install these into /usr/lib/
This version correctly links in libpthread into libgtest.
The option -lgtest is attempting to link the dynamic library libgtest.so. You
wish to link the static library /home/user/gtest-1.7.0/lib/.libs/libgtest.a.
Instead of:
g++ main.cpp -I/home/user/gtest-1.7.0/include -L/home/user/gtest-1.7.0/lib/.libs -lgtest -pthread
use:
g++ main.cpp -I/home/user/gtest-1.7.0/include /home/user/gtest-1.7.0/lib/.libs/libgtest.a -pthread
Note that your commandline supplies no name for the resulting executable, which will default
to a.out. If you want it called, e.g. mytest, then do:
g++ -o mytest main.cpp -I/home/user/gtest-1.7.0/include /home/user/gtest-1.7.0/lib/.libs/libgtest.a -pthread
Use -pthread instead of -lpthread (for linking with pthread-library), while you using gtest in your executable.
OR
Move the -lpthread after libgtest.a (sequence matters).
To answer we probably need more information, are you on a 64 bit machine and downloaded a 32 bit library?
I have a program that I am writing and that needs to calculate some hashes. I need SHA, MD, HMAC algorithms. That is why I chose openssl as solution.
My code is the following:
#include <openssl/md4.h>
void calc();
void calc(unsigned char* data, unsigned long len) {
unsigned char* h = new unsigned char[128];
MD4(data, len, h);
}
Compiler returns me the following:
myfile.cpp:(.text+0x3e): undefined reference to `MD4' collect2: ld
returned 1 exit status
I compile simply using:
g++ myfile.cpp -o myapp.o
under Linux Fedora.
I downloaded openssl libraries from here and compiled them cby using ./configure and then make install in the downloaded untarpalled directory. I also copied in /usr/local/include directory the include directory in the one I downloaded so that headers can be found by compiler because /usr/local/include is in my $PATH env var.
However the problem is that the linker cannot find the function. I understand that the reason might be two:
The compiler can find headers but cannot find implementations.
There are problems because openssl is written in C not in C++.
How should I proceeed? Thankyou
Edit1
I actually changed something in my openssl installation.
I installed openssl again and I could see that it places everything under /usr/local/ssl where I can find /usr/local/ssl/include and /usr/local/ssl/lib directories. I change my compilation string in:
g++ -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl -lcrypto
In the directories that I mentioned before I can find, respectively, /usr/local/ssl/include/openssl directory with all headers there and /usr/local/ssl/lib/libssl.a and /usr/local/ssl/lib/libcrypto.a libraries.
Before I did this change when I used the old compilation command, the compiler was telling me: Cannot find -lssl. With these changes, now it can find libs and headers, but ld always fails in the same way:
myfile.cpp:(.text+0x3e): undefined reference to `MD4' collect2: ld
returned 1 exit status
A little disappointed.
What do you think?
Linking against openssl usually requires -lssl.
g++ -o myapp myfile.cpp -lssl
By the way, it sounds like you may have done the installation a little incorrectly.
You shouldn't have to copy header files anywhere. And you may not have copied the shared libraries anyway.
The compilation should go something like this:
./configure --prefix=/usr/local/openssl
make
make install
And then you compile your program like:
g++ -c -o myapp1.o myfile1.cpp -I/usr/local/openssl/include
g++ -c -o myapp2.o myfile2.cpp -I/usr/local/openssl/include
g++ -o myapp myapp1.o myapp2.o -I/usr/local/openssl/include -L/usr/local/openssl/lib -lssl -lcrypto
The error is caused because you do not link the program to the openssl library during compilation.
Fix it with
g++ myfile.cpp -o myapp.o -lssl
See OpenSSL link options -lssl and -lcrypto in GCC
for how to link a program to openssl.
I compiled my normal cpp files to .o, and my cuda .cu files to .co
I want to link these so I can call the cuda stuff from my normal C++ file
Here is my linker command that Make is running:
g++ -I ../readers/ -I../writers -I../common/ -I /home/dcole/software/xerces-c-3.1.1/src -I /home/dcole/NVIDIA_GPU_Computing_SDK/C/common/inc/ -I /usr/local/cuda/include -O3 -fPIC -fopenmp -DFIX_PAULI -DFIX_YAMA -DUSING_CUDA -o YamaguchiGPU YamaguchiMain.o YamaguchiDecomp.o cuYamaguchi.co -L/usr/lib64/ ../../lib/IDT.a ../../lib/Linux/libxerces-c.a ../../lib/Linux/libfftw3f.a -lcurl -lidn -ldl -lssl -lm -lpthread -lcuda -L/usr/local/cuda/lib64/libcudart.so
So I am definitly linking cuda, and cudart, but yet I get this:
cuYamaguchi.co: In function `__sti____cudaRegisterAll_46_tmpxft_00003190_00000000_4_cuYamaguchi_cpp1_ii_init_gpu()':
tmpxft_00003190_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x1b4): undefined reference to `__cudaRegisterFatBinary'
tmpxft_00003190_00000000-1_cuYamaguchi.cudafe1.cpp:(.text+0x20f): undefined reference to `__cudaRegisterFunction'
The Cuda file is being linked without problems but it looks like you might have forgotten to define some necessary function (like cudaRegisterFatBinary).
Upgrading to gcc 4.7.0 or higher should fix this horrid linker issue.
I was using an absolute search path in the linker to _libcudart.so_. I changed the -L to point to just the folder, then added -libcudart so it would search the folder for that lib.