Install external library in C++ Dev-Cpp - c++

I am trying to install the FreeImage library in C++ using Dev-Cpp on Windows 10, i put the .h files in the corresponding folder and i added the directories in Dev-cpp, the .DLL file i put it in the folder: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin that it's where i have installed Dev-Cpp,also a .lib file i put it in the next folder: C:\Program Files(x86)\Dev-Cpp\MinGW64\lib that also it's where i have installed Dev-Cpp, i added -l FreeImage to the linker too.
when i compile the code the .h files are found correctly, but Dev-Cpp gives me errors of type Undefined reference to,i understand this is because C++ can't found where it's the functions defined.
Code:
#include <iostream>
#include <FreeImagePlus.h>
int main(){
fipImage img;
img.load("Goten.jpg");
return 0;
}
Errors:
C:\Users\admin\AppData\Local\Temp\ccjljTTu.o Aburrido2.cpp:(.text+0x36): undefined reference to `__imp__ZN8fipImageC1E15FREE_IMAGE_TYPEjjj'
C:\Users\admin\AppData\Local\Temp\ccjljTTu.o Aburrido2.cpp:(.text+0x53): undefined reference to `__imp__ZN8fipImage4loadEPKci'
C:\Users\admin\AppData\Local\Temp\ccjljTTu.o Aburrido2.cpp:(.text+0x68): undefined reference to `__imp__ZN8fipImageD1Ev'
C:\Users\admin\AppData\Local\Temp\ccjljTTu.o Aburrido2.cpp:(.text+0x7f): undefined reference to `__imp__ZN8fipImageD1Ev'
C:\Users\admin\Desktop\Programacion\collect2.exe [Error] ld returned 1 exit status
Linker:
-static-libgcc -lFreeImage
What i need to do? - Sorry for my english.

Related

Resolving Linker error MySQL Connector/C++

I would like to be able to connect from my c++ program to a local MySQL instance, but the following minimal file testfile.cpp does not compile and returns undefined references:
#include <mysqlx/xdevapi.h>
using namespace ::mysqlx;
int main()
{
printf("Hello world!\n");
return 0;
}
I suspect to not use the right compile flags. When I use the command
c++ -o test1 -std=c++11 -lmysqlcppconn8 -I /usr/include/mysql-cppconn-8/ testfile.cpp
I am getting the following error messages (translated to English):
/tmp/cc02ZbBr.o: In the function "mysqlx::abi2::r0::string::traits<char>::to_str[abi:cxx11](mysqlx::abi2::r0::string const&)":
testfile.cpp:(.text._ZN6mysqlx4abi22r06string6traitsIcE6to_strB5cxx11ERKS2_[_ZN6mysqlx4abi22r06string6traitsIcE6to_strB5cxx11ERKS2_]+0x2e): undefined reference to "mysqlx::abi2::r0::string::Impl::to_utf8[abi:cxx11](mysqlx::abi2::r0::string const&)"
/tmp/cc02ZbBr.o: In the function "mysqlx::abi2::r0::DbDoc::DbDoc()":
testfile.cpp:(.text._ZN6mysqlx4abi22r05DbDocC2Ev[_ZN6mysqlx4abi22r05DbDocC5Ev]+0x1b): undefined reference to "vtable for mysqlx::abi2::r0::DbDoc"
/tmp/cc02ZbBr.o: In the function "mysqlx::abi2::r0::DbDoc::~DbDoc()":
testfile.cpp:(.text._ZN6mysqlx4abi22r05DbDocD2Ev[_ZN6mysqlx4abi22r05DbDocD5Ev]+0xf): undefined reference to "vtable for mysqlx::abi2::r0::DbDoc"
/tmp/cc02ZbBr.o: In the function "mysqlx::abi2::r0::Value::print(std::ostream&) const":
testfile.cpp:(.text._ZNK6mysqlx4abi22r05Value5printERSo[_ZNK6mysqlx4abi22r05Value5printERSo]+0x88): undefined reference to "mysqlx::abi2::r0::common::Value::print(std::ostream&) const"
/tmp/cc02ZbBr.o:(.data.rel.ro._ZTCN6mysqlx4abi22r05ValueE0_NS1_6common5ValueE[_ZTVN6mysqlx4abi22r05ValueE]+0x18): undefined reference to "typeinfo for mysqlx::abi2::r0::common::Value"
/tmp/cc02ZbBr.o:(.data.rel.ro._ZTCN6mysqlx4abi22r05ValueE0_NS1_6common5ValueE[_ZTVN6mysqlx4abi22r05ValueE]+0x20): undefined reference to "mysqlx::abi2::r0::common::Value::print(std::ostream&) const"
/tmp/cc02ZbBr.o:(.data.rel.ro._ZTIN6mysqlx4abi22r05ValueE[_ZTIN6mysqlx4abi22r05ValueE]+0x28): undefined reference to "typeinfo for mysqlx::abi2::r0::common::Value"
collect2: error: ld returned 1 exit status
The header from this file comes from a sample code on MySQL Connector/C++'s Github.
This question on SO seems relevant but the syntax/directories might be outdated. In any case, I do not know how to adjust the answers given there to my situation and location of libraries. Therefore I am asking for help here.
More information:
I'm running Linux Ubuntu 18.04, MySQL version 8.0.19 and have the following files in /usr/lib/x86_64-linux-gnu/
libmysqlcppconn.so
libmysqlcppconn.so.7.8.0.19
libmysqlcppconn.so.7
but I do not know how to refer to them.
In /usr/include/mysql-cppconn-8/ I have the directories jdbc/, mysql/ and mysqlx/.
I installed the following binary packages using the apt package manager: libmysqlcppconn-dev, libmysqlcppconn7, libmysqlcppconn8-1 and libmysqlcppconn8-2 (which is probably overkill but according to the installation guide one has to install quite a few of these libraries).
which mysql returns /usr/bin/mysql
When you compile source files and link binaries with object files and libraries, the order does matter. Shared libraries providing exported symbols must follow object files and other shared libraries importing these symbols. In your case, the shared library must be placed in the end of the c++ command invitation:
c++ -o test1 -std=c++11 -I /usr/include/mysql-cppconn-8/ testfile.cpp -lmysqlcppconn8
The undefined symbols discovered after compiling testfile.cpp will be imported from the following libmysqlcppconn8.so. Linkers doesn't remember exported symbols from prior libraries. For more information read this nice article: Why does the order in which libraries are linked sometimes cause errors in GCC.

Undefined reference to error in Portaudio

I'm trying to use PortAudio for audio recording through a microphone. But I get a bunch of errors -
Compiling single file...
--------
- Filename: C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples\paex_record.c
- Compiler Name: TDM-GCC 4.9.2 64-bit Debug
Processing C source file...
--------
- C Compiler: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\gcc.exe
- Command: gcc.exe "C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples\paex_record.c" -o "C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples\paex_record.exe" -g3 -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -L"C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples" -g3
C:\Users\Gumm\AppData\Local\Temp\ccih6neG.o: In function `main':
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:224: undefined reference to `Pa_Initialize'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:227: undefined reference to `Pa_GetDefaultInputDevice'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:234: undefined reference to `Pa_GetDeviceInfo'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:238: undefined reference to `Pa_OpenStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:249: undefined reference to `Pa_StartStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:255: undefined reference to `Pa_Sleep'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:253: undefined reference to `Pa_IsStreamActive'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:260: undefined reference to `Pa_CloseStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:303: undefined reference to `Pa_GetDefaultOutputDevice'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:310: undefined reference to `Pa_GetDeviceInfo'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:314: undefined reference to `Pa_OpenStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:327: undefined reference to `Pa_StartStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:332: undefined reference to `Pa_Sleep'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:332: undefined reference to `Pa_IsStreamActive'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:335: undefined reference to `Pa_CloseStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:342: undefined reference to `Pa_Terminate'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:349: undefined reference to `Pa_GetErrorText'
collect2.exe: error: ld returned 1 exit status
Compilation results...
--------
- Errors: 1
- Warnings: 0
- Compilation Time: 0.53s
I know this is a linker error but I am unable to find any .lib file from my download of portaudio. How do I resolve this issue?
< /Hey >
It looks like you are trying to build one of the port audio examples, without first building and/or linking the portaudio library!
Building portaudio for windows
Since your on Windows, there's two main ways to build portaudio (official docs reference):
With Visual Studio (VS) : The portaudio download provides a VS project that you have to change a few minor things before it should (hopefully) compile.
With MinGW : A command line version of building portaudio on windows. You will need to install MinGW if you haven't already, but I think this method is much easier than my attempts with Visual Studio in the past.
Either technique you use will generate a static .lib file, which you can then be used to link to your project (i.e. the source file you are trying to compile).
Linking portaudio
Visual Studio
So since your on Windows, I would recommend doing this in Visual Studio (create a empty c++ command line program, and add the paex_record.c file ) if you want to have a setup project ready to go. Below is a quick way to setup a static lib in VS.
Reference the library header (portaudio.h) in Project
Properties->C/C++->General->Additional Include Directories
Reference the .lib (portaudio.lib) in Project Properties->Linker->Input
More info on creating and using static libs.
MinGW
It's actually much simpler with MinGW in my opinion but if you aren't used to working in the command line you might not prefer it.
Assuming you have your project directory with three files (for simplicity):
Project Folder
|paex_record.c
|portaudio.lib
|portaudio.h
Then the compile command (source) is:
cd /Project/Directory
gcc paex_record.c -lportaudio

Windows 8 Eclipse unable to link library C++

I am trying to link a driver to my project in Eclipse. The driver has a header file "cassandra.h" and a library cassandra.lib . I am able to add the header file successfully in my eclipse. I have added the name of the library as "cassandra" in Libraries tab on eclipse as the screen shot below shows.
In Library Paths i am trying to add the location of this library. However my project still fails to compile. I cannot seem to figure out why this is happening.
The lib folder contains cassandra.lib and cassandra_static.lib. I have tried both files but it does not seem to work. The bin folder contains cassandra.dll. I have also tried to load cassandra.dll but in this case the compiler says "cassandra.dll: file not recognized: File format not recognized". I had no problems loading these libraries in ubuntu.
Small program to test :
#include <cassandra.h>
#include <stdio.h>
#include <iostream>
int main() {
/* Setup and connect to cluster */
CassFuture* connect_future = NULL;
CassCluster* cluster = cass_cluster_new();
return 0;
}
The error in compiling :
'Invoking: Cross G++ Linker'
g++ -L"E:\cassandra-cpp-driver-2.2.2-win64-msvc140\lib" -o "simple.exe" ./src/simple.o -lcassandra
./src/simple.o: In function `main':
E:\workspace\simple\Debug/../src/simple.cpp:17: undefined reference to `cass_cluster_new'
collect2.exe: error: ld returned 1 exit status
make: *** [simple.exe] Error 1

Shared library compiles but has undefined references

I have two projects. Project "vDevice" compiles into "libvDevice.so". This library is then used by the other project "videoViewer", which compiles into a binary "app_videoViewer". These were both working fine before I added a call to avdevice_reigster_all() in one of vDevice's files.
vDevice.so compiles and links with no errors. In the makefile I have -L${FFMPEG_PATH} (where all the libav*.a files are located), and -l avformat, avcodec, avutil, asound, avdevice, and bz2 (in that order).
When I try to make videoViewer now, I get this error:
Linking application app_videoViewer ...
/path/to/lib/libvDevice.so: undefined reference to `avdevice_register_all'
collect2: error: ld returned 1 exit status
For videoViewer I added the same things to the makefile, linking to avformat, avcodec, avutil, asound, avdevice, and bz2, all before vDevice... what am I missing?

Errors while trying to compile OpenCV project on Dev C++

Im getting this error:
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xdf): undefined reference to `cv::imread(std::string const&, int)'
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xdec): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xe41): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
d:\devc\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o: bad reloc address 0x20 in section `.text$_ZSt4sqrtf[__ZSt4sqrtf]'
D:\devc\opencv\projekty\test 3 opencv\test 3 opencv\collect2.exe [Error] ld returned 1 exit status
What i did in Dev Options:
I have added this command line to compiler:
-L"C:\opencv\build\x86\vc11\lib" -lopencv_highgui248 -lopencv_core248 -lopencv_imgproc248 -lopencv_calib3d248 -lopencv_video248 -lopencv_features2d248 -lopencv_ml248 -lopencv_highgui248 -lopencv_objdetect248 -lopencv_contrib248 -lopencv_legacy248 -lopencv_flann248
This lane to linker options:
-static-libgcc -lopencv_highgui248 -lopencv_core248 -lopencv_imgproc248 -lopencv_calib3d248 -lopencv_video248 -lopencv_features2d248 -lopencv_ml248 -lopencv_highgui248 -lopencv_objdetect248 -lopencv_contrib248 -lopencv_legacy248 -lopencv_flann248
In directiories i have added:
binaries: D:\devc\opencv\build\x86\vc11\bin
libs: D:\devc\opencv\build\x86\vc11\lib
headers C: D:\devc\opencv\build\include\opencv2 D:\devc\opencv\build\include\opencv D:\devc\opencv\build\include
headers C++: same as above
I have added opencv path D:\devc\opencv to PATH variable
My dev C++ version is: 5.7.0, OpenCV: 2.4.8
Anyone know how to fix that?
EDIT
Same problem using CodeBlock
Did you link Source2 to collect2 properly? Source2.cpp should be compiled into an object file before linking with your main program.
If I am not mistaken, the problems are not related to linking libraries it is because imread and imwrite shouldnt be like you called
imread(string, mat)
But you called
imread(string, int)
So it gives error. Same with other lines.
Build the libraries using CMake and CodeBlocks as given in here till step 3 of codeblock settings.
Then include the following as given in the blog to Devc++ C and C++ Includes tab
C:\OpenCV\my_build\install\include
C:\OpenCV\my_build\install\include\opencv
C:\OpenCV\my_build\install\include\opencv2
since you have included opencv and opencv2, remove /opencv2/..and /opencv ..in the header files.
and add the below line to libraries in Devc++
C:\OpenCV\my_build\install\x64\mingw\lib
also add all the .dll.a files in C:\OpenCV\my_build\install\x64\mingw\lib to Project Options.
Copy all the dll files from opencv\my_build\install\x64\mingw\bin and paste to folder where EXE of your program would be built.