/usr/bin/ld: cannot find -lCImg - eclipse-cdt

I am newbie in C++ and Eclipse simultaneously...
I want to use CImg library but when I just used a line for it I have the problem that it is described below :
My code is:
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg <unsigned char> img(640,400,1,3);
return 0;}
and the error that I get is :
/usr/bin/ld: cannot find -lCImg
collect2: ld returned 1 exit status
I have searched a lot yesterday and I have tried many things that I found.
I tried almost everything for X11 library and pathread.
I changed many times the flags in the settings of the project...
Thank you in advance.
PS: I know that there is a similar(almost the same question) here g++: No such file or directory? but in my case I can not change the makefile.

CImg is a template-based library that is compiled 'on the fly' with your program, so it is not pre-compiled and thus doesn't have a libCImg.so or libCImg.a files associated to it.
You just don't need an option '-lCImg' when you call g++. Eventually, if you are using the display capabilities of CImg (which is the default behavior), you need to add
-lX11 -lpthread
on your compilation line, but that is all (and if you don't use CImgDisplay at all, those dependencies can be even removed by putting
-Dcimg_display=0
when compiling with g++).

Related

Including expect/tcl library for C/C++

Recently I found an example of how to use the expect library in C++. I tried to compile it, but the compiler (g++) said, that tcl8.5/expect.h doesn't exists. So I tried to include tcl8.6/expect.h - still the same error. I checked the /usr/include/ directory and I wasn't surprised when I've noticed, that there is no tcl8.x directory.
I've searched for files with "expect" in their name. Here's what I found:
/usr/include/expect_tcl.h
/usr/include/expect_comm.h
/usr/include/expect.h
Unfortunately when I tried to include any of these I got the following list of errors during compilation:
> g++ test.cpp -Wall -std=c++0x -ltcl8.6 -lglog -o test
/tmp/cce8k1BA.o: In function `task(std::string const&, std::string const&, std::string const&)':
test.cpp:(.text+0x16): undefined reference to `exp_is_debugging'
test.cpp:(.text+0x20): undefined reference to `exp_timeout'
test.cpp:(.text+0x38): undefined reference to `exp_popen'
etc...
How can I solve this problem?
[EDIT]
When I tried to link it with the expect lib (-lexpect) I got the following error:
/usr/bin/ld: cannot find -lexpect
collect2: error: ld returned 1 exit status
I'm sure that both - tcl8.6 and expect 5.45-4 are installed.
The usual way of distributing Expect these days puts the shared library in a non-standard location and loads it dynamically by full pathname. This works well and is minimal fuss for most people, but does make it rather hard to use Expect's C interface in your own code.
The easiest way is going to be to build your own copy from source, especially as that will give you control over how exactly it was built. This can particularly include keeping the majority of symbols in the library instead of stripping them on install, which will help a lot with debugging. You probably ought to use the current supported version. (Yes, it's a release from several years ago. It doesn't need a lot of support effort most of the time.)
You haven't linked to the expect library during your build. Add -lexpect to your g++ command.

Code::Blocks SDL2.0 "undefined reference to 'IMG_Load'"

I'm trying to use c++, SDL, and SDL-image to make a game; I'm using Code::Blocks as my IDE, and I'm having some trouble.
I've downloaded the latest mingw SDL development files, and the latest mingw SDL-image development files.
I've placed all the SDL-image stuff into the same directory as the SDL stuff (merging the one into the other).
I've added the x86_64-w64-mingw32/include and x86_64-w64-mingw32/lib directories to my Code::Blocks search directories.
My linker settings are as follows:
-lmingw32
-lSDL2main
-lSDL2
-lSDL2_image
-lopengl32
-lglu32
(Obviously I'm using openGL as well, but I don't think that's involved here).
I have the correct #includes as far as I can tell:
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_opengl.h>
But I'm still getting the error: undefined reference to 'IMG_Load'
Here's the build log:
obj\Release\gfx_Texture.o:gfx_Texture.cpp:(.text+0xd7): undefined reference to `IMG_Load'
obj\Release\gfx_Texture.o:gfx_Texture.cpp:(.text+0x1dd): undefined reference to `SDL_FreeSurface'
obj\Release\gfx_Texture.o:gfx_Texture.cpp:(.text+0x1f4): undefined reference to `SDL_FreeSurface'
g:/program files(x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: obj\Release\gfx_Texture.o: bad reloc address 0x4 in section `.text.startup'
g:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
And the actual code:
SDL_Surface* image = IMG_Load(file);
Where file is a char*.
I understand that there have been some changes to the way SDL_Surfaces work in SDL 2.0 as compared to SDL 1.2 (I'm trying to migrate, both from 1.2 to 2.0 and from MVSC to C::B), so could that have something to do with it? Am I using IMG_Load wrong?
Your help is much appreciated, and I'll supply any missing info on request if it'll clarify anything.
One more thought: The latest version of SDL is 2.0.1, yet the latest version of SDL_image is 2.0.0. Do I need those versions to match?
This happen When the program doesn't linker correctly at the executed time
for example:
asas#asas:~/SDL$ g++ -Wall SDL_program.cpp -lSDL2
/tmp/cc1eC6CK.o: InfunctionLTexture::loadFromFile(std::__cxx11::basic_string<char,std::char traits<char>, std::allocator<char> >)':
SDL_program.cpp:(.text+0x7d): **undefined reference toIMG_Load'**
As you can see above miss linker -lSDL2_image .
Is possible too, that you have SDL1.2 and SDL2 at the same root and again Code blocks hasn't linked correctly
Well don't I feel dumb. When I was working in MVC the x86 prefix meant 32-bit; for some reason, it means 64-bit in C::B, and the i686 prefix means 32-bit.
I encountered such an error, and all I did was check if my linker texts are correctly written check if you have typed "ISDL2_image" instead of "lSDL2_image"
(write small 'L' then SDL2 not cap 'I' then SDL2)for SDL2 projects.
for SDL1 just change the '2's into '1's. 👍

Errors while trying to compile with external libraries

I have downloaded the mimetic library installation files,
and followed the INSTALL instructions.
./configure
a script that creates the make file after checking a series of things.
make
compiles the cpp files, after this different .o and .lo files appear in the original folder.
make install
seems to do a lot but the only thing that I seem to notice is that a mimetic directory
appears under /usr/local/include with all the header files.
than I try to compile the most simple main file possible:
(as offered in the library site : original example )
#include <mimetic/mimetic.h>
using namespace mimetic;
int main()
{
MimeEntity me;
return 0;
}
I am compiling with following command ( on CentOS 5.7, gcc version : 4.1.2 ):
g++ mimetic.cpp
The error I get:
/tmp/ccWnsteO.o: In function `main':
mimetic.cpp:(.text+0x80): undefined reference to `mimetic::MimeEntity::MimeEntity()'
mimetic.cpp:(.text+0x91): undefined reference to `mimetic::MimeEntity::~MimeEntity()'
collect2: ld returned 1 exit status
From this I understand that the header files are found but the source/library itself
is missing.
the MimeEntity constructor declaration appears in : /usr/local/include/mimetic/mimeentity.h
when I do a search for mimeentity I get the following :
/home/mimetic-0.9.7/mimetic/mimeentity.o
/home/mimetic-0.9.7/mimetic/mimeentity.h
/home/mimetic-0.9.7/mimetic/mimeentitylist.h
/home/mimetic-0.9.7/mimetic/mimeentity.cxx
/home/mimetic-0.9.7/mimetic/.libs/mimeentity.o
/home/mimetic-0.9.7/mimetic/mimeentity.lo
/home/mimetic-0.9.7/mimetic/.deps/mimeentity.Plo
/usr/local/include/mimetic/mimeentity.h
/usr/local/include/mimetic/mimeentitylist.h
I've tried with a search path to the libraries but the same error appears
g++ mimetic.cpp -L/home/mimetic-0.9.7/mimetic/
Something else strange is happening, when I try to compile the main mimetic.cpp file
with the line
MimeEntity me;
changed to
MimeEntity me();
it compiles.
You are getting a linker error simply because you are not referencing the library when compiling the test source file. It needs to be something like:
g++ mimetic.cpp -l<libraryname>
The reason it compiles when you add the braces is that you are really declaring a function called 'me' that returns a MimeEntry. While it compiles, it does not do what you want.
The command you are using to build your mimetic example seems incomplete. You are specifying library search patch (-L) but not the library itself.
Make sure that -L option specified the location of the mimetic library
Add -l'the-name-of-the-mimetic-library'. My guess would be -lmimetic
Add -I (that is capital i) option for the location of the headers.

GMP Library, compile error in C++, MinGW, Code::Blocks

I have built GMP for MinGW. The IDE I'm using is Code::Blocks. I don't have any problems with C functions of GMP. But I'm having problem with C++. The program I tried to run is as simple as this,
#include<iostream>
#include<gmpxx.h>
using namespace std;
main()
{
mpz_class a;
a=12345;
cout<<"value"<<a<<"\n";
return 0;
}
And the Errors I get are
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osmpz.o):osmpz.cc|| undefined reference to `__gmpz_get_str'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osfuns.o):osfuns.cc:(.rdata+0x1c)||undefined reference to `__gmp_asprintf_memory'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osfuns.o):osfuns.cc:(.rdata+0x20)||undefined reference to `__gmp_asprintf_reps'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osdoprnti.o):osdoprnti.cc|| undefined reference to `__gmp_doprnt_integer'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osdoprnti.o):osdoprnti.cc|| undefined reference to `__gmp_asprintf_final'|
||=== Build finished: 5 errors, 0 warnings ===|
Now, some additional data:
I don't have any problem with C functions. And also, if I remove cout<< statement the file compiles and runs fine. The problem is probably with overloaded operators.
libgmpxx.a and libgmp.a are linked with compiler. It can be seen in the error messages too...
The problem is probably with the libgmpxx.a alone. So, I built the Library again, but the files are same.
I used this tutorial build GMP with MSYS for MinGW. http://www.cs.nyu.edu/exact/core/gmp/ and http://suchideas.com/journal/2007/07/installing-gmp-on-windows/
The version of GMP I'm using is 5.0.4.
So, what I want to know is, what could be the problem? And how could it be solved?
And, if unsolvable and if you have the working files for 5.0.4 version, please share it. :(
I suspect the command to build your program specifies the libgmp* libraries in the wrong order. Make sure the libgmp.a library is specified after the libgmpxx.a library:
-lgmpxx -lgmp
If they are specified in the other order, then when pulling in dependencies from libgmpxx.a library, the libgmp.a library won't be searched.
From the ld linker's docs on the -l option:
The linker will search an archive only once, at the location where it
is specified on the command line. If the archive defines a symbol
which was undefined in some object which appeared before the archive
on the command line, the linker will include the appropriate file(s)
from the archive. However, an undefined symbol in an object appearing
later on the command line will not cause the linker to search the
archive again.
See the -( option for a way to force the linker to search archives
multiple times.
You may list the same archive multiple times on the command line.

Compiling error opencv

I'm working on opencv implemented codes which I downloaded already by svn. These codes such as SIFT or SURF and codes for opencv were working perfectly before, but suddenly I got this error while I want to compile any code concerns opencv
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
So how can I solve it please, I have red already some problems but they were not helpful with my case, such as I have to change the compilation code from g++ SIFT.cpp -o SIFT .... to g++ -o SIFT SIFT.cpp .... but it didn't work out with me.
Thank you.
I know this is old, but I just had a similar problem (with OpenCV 2.4.4a (and also 2.4.1)) and this was the first thing that popped up on google.
I disabled the "precompiled headers" option in the OpenCV configuration (do it from cmake-gui, or pass -DENABLE_PRECOMPILED_HEADERS=OFF to cmake when generating), and everything works fine.
main is the starting point of execution of any C++ program. And you probably have forgot to build the source file that has main function. Since the file you built doesn't has main, linker failed to find the starting point of execution.
g++ SIFT.cpp fileThatHasMainFunctionDefinition.cpp -o SIFT
or alternatively provide the main in SIFT.cpp itself.