Problems compiling an external library on linux - c++

So I am trying to compile the libssh2 library on linux, but when I try to compile the
example it comes up with a lot of errors, and even though I include the headerfile it asks for, it still asks for it.
Here are the error messages and the resulting messages:
~/ gcc -include /home/Roosevelt/libssh2-1.2.5/src/libssh2_config.h -o lolbaise /home/Roosevelt/libssh2-1.2.5/example/scp.c
/home/Roosevelt/libssh2-1.2.5/example/scp.c:7:28: error: libssh2_config.h: No such file or directory
/home/Roosevelt/libssh2-1.2.5/example/scp.c: In function 'main':
/home/Roosevelt/libssh2-1.2.5/example/scp.c:39: error: storage size of 'sin' isn't known
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'AF_INET' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: (Each undeclared identifier is reported only once
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: for each function it appears in.)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'SOCK_STREAM' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:87: error: invalid application of 'sizeof' to incomplete type 'struct sockaddr_in'
Here is the new errors:
scp.c:(.text+0x106): undefined reference to `libssh2_init'
scp.c:(.text+0x1fe): undefined reference to `libssh2_session_init_ex'
scp.c:(.text+0x234): undefined reference to `libssh2_session_startup'
scp.c:(.text+0x288): undefined reference to `libssh2_hostkey_hash'
scp.c:(.text+0x36f): undefined reference to `libssh2_userauth_password_ex'
scp.c:(.text+0x3e7): undefined reference to `libssh2_userauth_publickey_fromfile_ex'
scp.c:(.text+0x437): undefined reference to `libssh2_scp_recv'
scp.c:(.text+0x531): undefined reference to `libssh2_channel_read_ex'
scp.c:(.text+0x5f8): undefined reference to `libssh2_channel_free'
scp.c:(.text+0x628): undefined reference to `libssh2_session_disconnect_ex'
scp.c:(.text+0x636): undefined reference to `libssh2_session_free'
scp.c:(.text+0x66e): undefined reference to `libssh2_exit'
collect2: ld returned 1 exit status

The header file is not included: libssh2_config.h
There is an inclusion directive in the source code, so you have to indicate the path to the header with the -I option: gcc -I/home/Roosevelt/libssh2-1.2.5/src
The -include option shall be used to include a header file which is not explicitly included in the source code with a #include directive.

I just cloned the current git build and went into the 1.2.5 relase but I'm unable to reproduce your problem.
./buildconf
./configure
make
works fine. What are you trying to do exactly?

Related

Installation and usage of TagLib in c++ project

In addition to my previous Q.
I have tried numerous sources in order to find the right way how to install taglib library for c++ and use it in my project.
I am including path
#include <taglib/tag.h>
i tried including just
#include <taglib>
but it did not work even tho /usr/include/taglib exists.
I am compiling my project using
g++ -Wall -pedantic -std=c++11 -ltaglib main.cpp -I taglib-1.11.1/toolkit
yet the demo from site
TagLib::FileRef f("Latex Solar Beef.mp3");
TagLib::String artist = f.tag()->artist(); // artist == "Frank Zappa"
throws
error: ‘FileRef’ is not a member of ‘TagLib’ TagLib::FileRef
f("Latex Solar Beef.mp3"); ^ main.cpp:5:18: error: expected ‘;’
before ‘f’ TagLib::FileRef f("Latex Solar Beef.mp3");
^ main.cpp:6:25: error: ‘f’ was not declared in this scope TagLib::String artist = f.tag()->artist(); // artist == "Frank
Zappa"
When i add #include <taglib/fileref.h>
it throws
main.cpp:(.text.startup+0x48): undefined reference to
TagLib::FileRef::FileRef(char const*, bool,
TagLib::AudioProperties::ReadStyle)' main.cpp:(.text.startup+0x50):
undefined reference toTagLib::FileRef::tag() const'
main.cpp:(.text.startup+0x68): undefined reference to
TagLib::String::~String()' main.cpp:(.text.startup+0x70): undefined
reference toTagLib::FileRef::~FileRef()'
main.cpp:(.text.startup+0x83): undefined reference to
`TagLib::FileRef::~FileRef()' collect2: error: ld returned 1 exit
status
What is the right way to install and use TagLib?
Try compiling in release mode by adding this option:
-O3
try to write in your cmakelist.txt
target_link_libraries(your_executable tag)

Undefined reference to Magick::Image ::Image() in eclipse c++

I am using Eclipse CDT on windows 7 64 bit and trying to work on Image Class using Image Magick but I am getting the below error-
#pragma warning(once: 4459) /* 'identifier' : declaration of 'foo' hides global declaration */
g++ "-LC:\\Development\\ImageMagick-7.0.3-Q16\\lib" "- LC:\\Development\\opencv\\MINGW\\x86\\bin" -o testOpencv.exe "src\\testOpencv.o" -llibopencv_features2d2410 -lCORE_RL_Magick++_ -lCORE_RL_MagickCore_ - lCORE_RL_MagickWand_ -llibopencv_objdetect2410 -llibopencv_contrib2410 - llibopencv_core2410 -llibopencv_flann2410 -llibopencv_gpu2410 - llibopencv_highgui2410 -llibopencv_imgproc2410 -llibopencv_ml2410 - llibopencv_legacy2410 -llibopencv_nonfree2410 -llibopencv_objdetect2410 - llibopencv_ocl2410 -llibopencv_photo2410 -llibopencv_stitching2410 - llibopencv_superres2410 -llibopencv_video2410 -llibopencv_videostab2410 - lopencv_ffmpeg2410 -llibopencv_ml2410
src\testOpencv.o: In function `main':
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:14: undefined reference to `Magick::Image::Image()'
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:15: undefined reference to `Magick::Image::read(std::string const&)'
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:16: undefined reference to `Magick::Image::display()'
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:16: undefined reference to `Magick::Image::~Image()'
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:16: undefined reference to `Magick::Image::~Image()'
collect2.exe: error: ld returned 1 exit status
14:28:39 Build Finished (took 847ms)
I have added includes file to compiler and Library files in the linker in Eclipse. The library file in Image magick installed folder look strange to me, as they are not '.dll' files. Please let me know if I am right and how do i rectify this.

Linker errors in libqt5network.so

Hello dear stack overflow users,
lately I tried to compile a qt5 project on my suse machine.
It seems that my linker refuses to link the libqt5network.so against openssl.
And I fail to understand why:
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_1_server_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_set_psk_client_callback'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_1_client_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_select_next_proto'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_get0_next_proto_negotiated'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_2_client_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_CTX_set_next_proto_select_cb'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_2_server_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `EC_curve_nist2nid'
This Method seems the culprit, which shall download some information of a book frome the worldcat book database by its public api:
void Worldcat::search(QString searchTerm){
if(book1!=NULL){
setIsbn(searchTerm);
QNetworkRequest request(apiUri+getIsbn()+QString("?method=getMetadata&format=json&fl=*"));
networkManager = new QNetworkAccessManager(this);
connect(networkManager,SIGNAL(finished(QNetworkReply*)),
this,SLOT(replyFinished(QNetworkReply*)));
networkManager->get(request);
}
}
qmake.pro file
http://pastebin.com/Qk83kLaQ
The Generated make file, it is huge therefore paste bin:
http://pastebin.com/KuF9Y0JS
I will answer it myself since I found the solution when my mongodb also refused to start, maybe it is usefeull to someone the following does help:
zypper in libopenssl-devel
rpm -e --nodeps libopenssl0_9_8
cd /usr/lib64/
ln -s libssl.so libssl.so.0.9.8
ln -s libcrypto.so libcrypto.so.0.9.8
Seems that tumble weed has a mess with its openssl librarys.
Where I found the solution:
https://stackoverflow.com/a/32406299/4958693
Original source:
https://jira.mongodb.org/browse/SERVER-20259

g++ undefined reference though all files included

I have the problem that as the g++ tries to link the object files I receive the following error:
11:29:13 **** Build of configuration Debug for project daytime ****
make all
'Building target: daytime'
'Invoking: Cross G++ Linker'
g++ -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o
./tcf/services/daytime.o: In function `command_get_time_of_day':
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:38: undefined reference to `json_read_string'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:40: undefined reference to `exception'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:43: undefined reference to `exception'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:52: undefined reference to `write_stringz'
makefile:46: recipe for target 'daytime' failed
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:54: undefined reference to `write_stringz'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:56: undefined reference to `write_errno'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:58: undefined reference to `json_write_string'
./tcf/services/daytime.o: In function `ini_daytime_service':
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:70: undefined reference to `add_command_handler'
collect2.exe: error: ld returned 1 exit status
make: *** [daytime] Error 1
I have no idea why this is the case since e.g. #include <tcf/framework/json.h>is included and found.
Didn't gcc compile the corresponding *.c files such that this linker error occurs?
What is the problem here?
Thank you.
It is not enough to include the header files; you also have to specify the libraries where those functions are defined.
To make the linker find all those methods/classes (json_read_string, write_stringz, exception) you need to reference the library. If e.g. they are contained in a library called libjson.so, you should do:
g++ -ljson -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o
(or add the library to the project options, if eclipse is managing your make files).
Or if it's another .o file, include that in the compilation (-> or in the project, if eclipse is creating the make file).

Compiling C++: undefined reference

I'm pretty new to C++ and I'm trying to compile my code. The command I'm using is g++ -o main --std=c++11 main.cpp channel.cpp. However I'm getting the following error message:
/tmp/ccLuJs81.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `gsc::Channel<int>::Channel()'
main.cpp:(.text+0x3a): undefined reference to `gsc::Channel<int>::put(int)'
main.cpp:(.text+0x4e): undefined reference to `gsc::Channel<int>::get(bool)'
collect2: error: ld returned 1 exit status
Does anyone know what's going on here? Thanks a lot!
Seems you declared a template in a header and defined it in a C++ file. This won't work. If you don't define your template in a header, you need to explicitly instantiate it in your C++ file, e.g. ,using
template class gcs::Channel<int>;
after the definition of all the methods.