Linking programs to C++ Project in Eclipse? Linux - c++

I am given the command to link programs:
g++ -o prog_name prog_name.cc -lsicklms-x -pthread
However, I'm not using the command line, I'm using eclipse.
My Project is called "Test" and I have only 1 class "main.cpp" that is this:
/*
* Test.cpp
*
* Created on: Dec 1, 2011
* Author: igvc
*/
#include <iostream>
#include <sicklms-1.0/SickLMS.hh>
using namespace std;
using namespace SickToolbox;
int main(int argc, char *argv[]) {
/* Specify device path and baud */
string dev_path = "/dev/ttyUSB0";
sick_lms_baud_t lms_baud = SickLMS::SICK_BAUD_38400;
/* Define buffers for return values */
unsigned int measurements[SickLMS::SICK_MAX_NUM_MEASUREMENTS] = {0};
unsigned int num_measurements = 0;
/* Instantiate the object */
SickLMS sick_lms(dev_path);
try {
/* Initialize the device */
sick_lms.Initialize(lms_baud);
/* Grab some measurements */
for(unsigned int i = 0; i < 10; i++) {
sick_lms.GetSickScan(measurements,num_measurements);
cout << "\t" << num_measurements << endl;
}
/* Uninitialize the device */
sick_lms.Uninitialize();
}
catch(...) {
cerr << "error" << endl;
return -1;
}
return 0;
}
I'm getting all these errors:
undefined reference to `SickToolbox::SickLMS::~SickLMS()`
undefined reference to `SickToolbox::SickLMS::GetSickScan(unsigned int*, unsigned int&, unsigned int*, unsigned int*, unsigned int*, unsigned int*, unsigned int*)'
undefined reference to `SickToolbox::SickLMS::Initialize(SickToolbox::SickLMS::sick_lms_baud_t)'
undefined reference to `SickToolbox::SickLMS::SickLMS(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
undefined reference to `SickToolbox::SickLMS::Uninitialize()'
So I think it's a linking problem. And I have that above command to link, which the tutorial says is required, but I'm not sure how to set it up in eclipse.
Where the code says #include sicklms-1.0/SickLMS.hh, I did go to Project>Properties>C/C++ Build>Settings>GCC C++ Compiler>Directories and added the directory to the .h file and that resolved that problem, but now I'm getting those errors. I went to GCC C++ Linker>Libraries>Library search path(-L) and added the sicktoolbox-1.0.1 directory, but i don't know what to put in the Libraries(-l) part.
Thanks for any help, I'm really stuck on this.

Presumably you are using Eclipse CDT?
Right-click on your project and select Properties from the context menu.
In the Properties dialog, select C/C++ Build->Settings->GCC C++ Linker->Libraries
In the Libraries box, click on the + button to add a new library, type sicklms
Your library must be in the linker's path. /usr/lib and /usr/local/lib are fairly standard. The library name must be libsicklms.a or libsicklms.so for -l as the linker prepends lib to the library name.
If sicklms was installed from source with ./configure && make && make install then the library should be in the standard library path i.e. either /usr/lib or /usr/local/lib otherwise, your problem is not your linker, but the way sicklms was installed.
If any of the above instructions are not doable, you need to let me know
a) Version of Eclipse (Galileo, Indigo, etc)
b) If you have CDT installed.
c) How sicklms was installed on your system (package manager, built from source, etc).

Based entirely on what you've written here, I think in the -l part you need to just add -lpthread -lsicklms-x. But that's assuming Eclipse provides enough smarts to replace a tool such as make(1), which is really fantastic for rebuilding large projects.
Try creating a Makefile in your project directory like this:
LDFLAGS=-L/path/to/sicklms-directory -lsicklms-x -lpthread
Running make then gives:
$ make main
g++ -L/path/to/sicklms-directory -lsicklms-x -lpthread main.cpp -o main
/usr/bin/ld.bfd.real: cannot find -lsicklms-x
collect2: ld returned 1 exit status
make: *** [main] Error 1
(It fails because I don't have your libraries available. But it does show the command line that was executed to try to build the source.)
You can probably make some easy changes for compiling Java programs too. I've only got super-simplistic Java sources easily available, but the following Makefile lets me re-build them very easily:
$ cat Makefile
.SUFFIXES: .java .class
.java.class:
javac $<
all: Echo.class Test.class Compress.class
$ make Echo.class Test.class
javac Echo.java
make: `Test.class' is up to date.
$ rm *class
$ make
javac Echo.java
javac Test.java
javac Compress.java
(Note that the indented line is indented with a tab. It must be a tab. make(1) is mighty archaic in some seriously inconvenient ways.)

Related

undefined reference to `WinMain' in eclipse IDE with cygwin (setup-x86_64)

I am currently doing unit testing for a project of c/c++ in eclipse IDE (Version: Luna Service Release 2 (4.4.2)) and I have recently upgraded my cygwin to cygwin64 to make it compatible with c++17 standard and my g++ version is g++ (GCC) 10.2.0, But I am not able to build my testsuites in eclipse, I have set the environment path to "C:\cygwin64\bin", But still I am getting the below error. Could you please help me with the below error:
Console output after building my project :
make all
Building file:
C:/Accurev/AngioJet_Development_ver1/CS/AngioJet/Firmware/src/ClinicalFeatures/door.cpp
Invoking: Cygwin C++ Compiler
g++ -DUNIT_TESTING - "C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/build/PicoZed_FSBL_bsp/ps7_cortexa9_0/include" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../testsupport/" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../testsupport/Source" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/Platform/Zynq7000" - I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/HostInterface" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/soup/treck/6_0_1_56/include" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../Einstein/src/Platform/Zynq7000" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../Einstein/src/Common" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/Common" -I"C:/Accurev/AngioJet_Development_ver1/CS/ut/testsuites/Firmware/hell/../../../../AngioJet/Firmware/src/ClinicalFeatures" -O0 -g -fprofile-arcs -ftest-coverage -Wall -c -fmessage-length=0 -MMD -MP -MF"src/door.d" -MT"src/door.d" -o "src/door.o" "C:/Accurev/AngioJet_Development_ver1/CS/AngioJet/Firmware/src/ClinicalFeatures/door.cpp"
Finished building: C:/Accurev/AngioJet_Development_ver1/CS/AngioJet/Firmware/src/ClinicalFeatures/door.cpp
Building target: helll.exe
Invoking: Cygwin C++ Linker
g++ -fprofile-arcs -o "helll.exe" ./src/door.o -lgcov -lbfd
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/10/../../../../lib/libcygwin.a(libcmain.o): in function `main':
/usr/src/debug/cygwin-3.3.6-1/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain'
collect2: error: ld returned 1 exit status
make: *** [makefile:47: helll.exe] Error 1
07:05:17 Build Finished (took 4s.531ms)
`*
I have uninstalled and reinstalled the softwares. Also I have built a new project from scratch which is building fine but whenever i try to build my project it is not building.
While doing unit testing in eclipse we create the project as c++ project and import the source files mentioned below and the structure is as follow:
Source file - door.cpp, door.h
door.h:
#include "global.h"
namespace lDOOR { void close( BasicTypes::UInt8 mode ); }
door.cpp:
#include "door.h"
void lDOOR::close(void)
{
//Normal Mode
close(BscMsg::NORMAL);
}
and we do the unit testing for the above functions present in .cpp file in the file created by us door_testsuite.h which is as follows:
#include <cxxtest/TestSuite.h>
class door_TestSuite: public CxxTest::TestSuite {
public:
void setUp(){}
void teardown(){}
void testDoorLDoorClose()
{
BscMsg::UInt8 mode = 2;
lDOOR::close(mode);
TS_ASSERT_EQUALS();
}};
And when I test the above code in cygwin terminal it executes completely fine.
This means there is no WinMain function, which is the entry point to Windows windows programs. Yes, confusing. You can choose to either build a program as a console program or windows program. (There are a few other types that are irrelevant) In a console program, the entry point is main (As with the entire world of computing), but in a windows program, it is WinMain. This question has a good answer that goes into depth about it, but you either need to switch the type of program to console, or (If your program is creating and using windows) add a WinMain function.
Sorry if this is confusing, it is difficult to differentiate between Windows, the OS, and windows, the type of program. Also, my knowledge on this subject is all from VSCode, so may be completely or partially incorrect.
TLDR: Either add a WinMain function, or switch to building your program as a windows program.

Using CGAL Libraries with Eclipse on Ubuntu 16.04

I am trying to run some "Hello world" tests with CGAL libraries under Eclipse Oxygen, but I am failing with a dozen of undefined reference errors.
I followed the suggested apt-driven installation method by running
sudo apt-get install libcgal-dev
sudo apt-get install libcgal-demo
But now I am completely lost on how to link the libraries and make Eclipse correctly include and use CGAL.
This is the program that I'm trying to build:
#include <iostream>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <sstream>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
int main()
{
Point_2 p(0, 0.3), q, r(2, 0.9);
{
q = Point_2(1, 0.6);
std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not
collinear\n");
}
{
std::istringstream input("0 0.3 1 0.6 2 0.9");
input >> p >> q >> r;
std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not
collinear\n");
}
{
q = CGAL::midpoint(p,r);
std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not
collinear\n");
}
return 0;
}
And this is an example of the errors that I'm receiving:
make all
Building target: exact
Invoking: Cross G++ Linker
g++ -L/usr/lib/x86_64-linux-gnu -L/usr/lib -o "exact" ./exact.o
./exact.o: In function `CGAL::Handle::Handle(CGAL::Handle const&)':
/usr/include/CGAL/Handle.h:55: undefined reference to
`CGAL::precondition_fail(char const*, char const*, int, char const*)'
makefile:44: recipe for target 'exact' failed
I tried to include the directories where the GCAL libraries are located in Eclipse under the Cross G++ Linker and Cross GCC compiler, but to no avail.
Unfortunately I am a total beginner both in C++ programming and in Eclipse!
Thanks for the Help!
I have suffered through this multiple times. :D
Here are the lessons I have learned*:
Do not download cgal from the ubuntu repository - download from their website and build from source
Make sure you have all the dependencies (boost, etc) installed
Right-click on your project -> Properties -> C/C++ Build ->Settings ->Tool Settings.
Under GCC C++ Linker:
add libraries CGAL,gmp,mpfr,boost_thread
set library search path: (your path)/CGAL-4.11.1/lib
Under GCC C++ Compiler: -> includes: add include path (yourpath)/CGAL-4.11.1/include/
Try now. If it still does not because you cannot dynamically link the right files, add "-rpath /home/merlin/UbuntuSoftware/CGAL-4.11.1/lib " under miscellaneous under the linker.
Hope that helps.
Merlin :)

C++ - Undefined reference to "sodium_init"

I am attempting to make a testing application using libsodium, however I am getting the error:
main.cpp:6: undefined reference to `sodium_init'
I ran the following commands to install in as the root user.
$ ./configure
$ make && make check
$ make install
This the code that is having the issue.
#include <stdio.h>
#include <sodium.h>
int main(int argc, char **argv)
{
if (sodium_init() == -1)
{
return 1;
}
printf("libsodium had no issues!\n");
return 0;
}
I am using CodeLite as my IDE, and my C++ compiler options are the following:
-g;-O0;-Wall;-lsodium
The options were default and I added -lsodium to the list.
Attempting to compile main.cpp directly from the terminal with the following command g++ -lsodium main.cpp throws the same error.
Could someone please help me with my issue.
Libraries for linking are searched in order, so you need to place the libraries after your local translation units:
g++ main.cpp -lsodium
In your IDE, make sure you add -lsodium as a linker argument.

c++ program using GMP library

I have installed GMP using the instruction on this website: http://www.cs.nyu.edu/exact/core/gmp/
Then I looked for an example program using the library:
#include <iostream>
#include <gmpxx.h>
using namespace std;
int main (void) {
mpz_class a, b, c;
a = 1234;
b = "-5678";
c = a+b;
cout << "sum is " << c << "\n";
cout << "absolute value is " << abs(c) << "\n";
cin >> a;
return 0;
}
But if I compile this using the command: g++ test.cpp -o test.exe, it says gmpxx.h: no such file or directory.
How can I fix this? I am kind of new to this. And I am using MinGW.
Get the actual version here GNU GMP Library. Make sure you configure it to be installed in /usr/lib (pass --prefix=/usr to configure).
Here you have documentation: GNU GMP Manual.
You are not using the lib correctly. I don't know if you can directly access mpx values
with C++ functions but, here you have a working example of what you wanted to achieve:
#include<iostream>
#include<gmp.h>
using namespace std;
int main (int argc, char **argv) {
mpz_t a,b,c;
mpz_inits(a,b,c,NULL);
mpz_set_str(a, "1234", 10);
mpz_set_str(b,"-5678", 10); //Decimal base
mpz_add(c,a,b);
cout<<"\nThe exact result is:";
mpz_out_str(stdout, 10, c); //Stream, numerical base, var
cout<<endl;
mpz_abs(c, c);
cout<<"The absolute value result is:";
mpz_out_str(stdout, 10, c);
cout<<endl;
cin.get();
return 0;
}
Compile with:
g++ -lgmp file.cpp -o file
Here is the correct procedure for setting up the current (as of 7/2/13) GNU bignum libraries with Eclipse CDT, MinGW, and msys for C++. To get through this, you should have used Unix or Linux before, as well as Windows, and you should have a vague recollection of programming and compiling programs. This is the culmination of over a week of research and hardcore frustration, so if I messed something up note it politely or I will blow you up with the power of my mind!
I assume you have already downloaded and installed Eclipse and MinGW and have installed msys into MinGW. You must install MinGW before msys!
Download the tarball for the GMP libraries from gmplib.org to ${gmp_download}. I downloaded the gmp-5.1.2.tar.xz because I have never used lzip and didn't know if it was available in msys.
Open up an msys window (essentially a bash shell). cd ${gmp_buid} and tar -Jxvf ${gmp_download}/gmp-x.x.x.tar.xz
Those tar options are different from what you may find elsewhere on the web! -Jxvf is right for xz (and I think lzip), but for gzip you use -xzvf.
cd gmp-x.x.x and run ./config.guess. Write down the output. You will need it next.
Run ./configure --prefix=${gmp_build} --build= --enable-cxx --with-gnu-ld
Apparently if you don't explicitly tell GMP to build for your platform it builds everything, which is bad. The cxx option builds the C++ libraries and --with-gnu-ld allows it to work with ld. Pretty straightforward.
make
make install
EX: suppose you installed to C:/gmp. You should have gmp/include/gmp.h and gmpxx.h. You should also have gmp/lib/libgmp.a, libgmp.la, libgmpxx.a, libgmpxx.la. You should also have a share directory with stuff in it.
Set up eclipse:
Go to project --> properties
Under C/C++ build --> Environment edit the PATH variable and add ${gmp_build}/include;${gmp_build}/lib
Under C/C++ build --> settings --> tool settings --> GCC Assembler --> general add ${gmp_build}/include as an include path.
Same place but --> GCC C++ compiler --> Includes add ${gmp_build}/include as an include path.
Same place --> GCC C++ compiler --> Miscellaneous add -lgmp -lgmpxx to the END of the line. THE END OF THE LINE!
Same place --> GCC C compiler Add the same include paths and miscellaneous options as before.
Same place --> MinGW C++ linker --> Libraries Add to the "Libraries (-l)" both gmp and gmpxx IN THAT ORDER! Now add ${gmp_build}/lib to "LIbrary Search Path (-L)"
Under C/C++ General --> Paths & Symbols --> Incudes Tab check that you have ${gmp_build}/include in your include directories for Assembly, C, and C++. If they aren't there you may have messed up an earlier step. They should be auto populated by Eclipse.
Same place --> Libraries Tab check that you have gmp and gmpxx IN THAT ORDER. It should already be populated.
Same Place --> Library Paths Tab Check for ${gmp_build}/lib which should already be there.
Hit "Apply" and make sure you rebuild the index or the changes won't take. Hit OK to close out.
Run this short program to verify your setup:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <gmp.h>
#include <gmpxx.h>
using namespace std;
int main ()
{
mpz_t p;
mpz_init_set_ui (p,3);
return 0;
}
Your compile commands should look similar to this:
g++ "-IC:\gmp\include" -O0 -g3 -Wall -c -fmessage-length=0 -lgmp -lgmpxx -o main.o "..\main.cpp" g++ "-LC:\gmp\lib" -o GMPDebug.exe main.o -lgmp -lgmpxx
Notes:
The order of the options is important. I don't know all of the whys, but if the second command line (which links the program) has the -lgmp -lgmpxx flags before the -o option, the linking will fail miserably.
The -l flag is a tricky one. It actually says "Go look in -L for liblibrary.a". In this case "Go look in C:\gmp\lib for libgmp.a and libgmpxx.a".
I have heard of bugs involving cout and the 64 bit version of eclipse, so I am using the 32 bit version, where I am seeing the same bug. :-)
Since there are very small examples in gmp library docs, I'm including exponentiation example for reference:
Program calculates 2 ^ 20000
#include <iostream>
#include <gmp.h>
using namespace std;
int main(void) {
mpz_t result, base;
mpz_inits(result,base,NULL);
mpz_set_str(base, "2", 10);
mpz_pow_ui(result, base, 20000);
mpz_out_str(stdout, 10, result);
return 0;
}
Compile:g++ -o gmp_pow_test gmp_pow_test.cpp -lgmp
Run :./gmp_pow_test
Install gmp library on Ubuntu with following: sudo apt-get install libgmp-dev libgmpxx4ldbl
You need to tell the compiler what libraries you want to use.
g++ -lgmp -lgmpxx file.cpp -o file
It is probably too late to be useful, but...
First, your program works just fine. As others pointed out, you need to (a) ensure that GMP library is installed (including its gmpxx extension, and all the relevant files), and (b) that you're telling the compiler where to find both the include files, and the libraries to link with.
In my case include files are in /opt/local/include, and the libraries are in /opt/local/lib (where Macports placed them :).
Here's the code:
#include <iostream>
#include <gmpxx.h>
using namespace std;
int main (void) {
mpz_class a, b, c;
a = 1234;
b = "-5678";
c = a+b;
cout << "sum of " << a << " and " << b << " is " << c << "\n";
cout << "absolute value is " << abs(c) << "\n";
// cin >> a;
return 0;
}
Here's the compile/link command:
clang++ -o gmpxx-tst -I/opt/local/include gmpxx-tst.cpp -L/opt/local/lib -lgmpxx -lgmp
Here's what invocation of gmpxx-tst produces:
$ ./gmpxx-tst
sum of 1234 and -5678 is -4444
absolute value is 4444
$
You'll need to tell the compiler where the header file is.
g++ test.cpp -I/path/to/directory/that/contains/the/header -o test.exe
I have tried so many solutions and all of them has some problems
Here is the best way to install GMP and eclipse
Follow this link
http://www.multigesture.net/articles/how-to-install-mingw-msys-and-eclipse-on-windows/
You need to make sure of the following that hasn't been mentioned there:
When installing MinGW choose a path that contains no space like "c:\MinGW"
Once installed, From start open MinGW installation manger
choose all the basics
-then under MinGW, choose all GMP libraries to be installed
Apply changes
After that you will install JDK, then Add "C:\Program Files\Java\jdk1.8.0_121\bin" to PATH system variable
After installing Eclipse go to:
GCC C++ compiler --> Miscellaneous add -lgmp -lgmpxx to the END of the line
MinGW C++ linker --> Libraries Add to the "Libraries (-l)" both gmp and gmpxx IN THAT ORDER
gooooo ahead.

Adding Boost Library to a C++ project in OS X Eclipse

I am have been attempting to get a C++ project setup using boost file system library using eclipse. I followed these directions to install boost on my system. The directions where pretty much
download
extract
run bootstrap.sh
run ./bjam architecture=combined
That seemed to go fine, no errors. I then fired up eclipse and created a new test project called test with a single file called test.cpp. The code in it is:
#include <stdio.h>
#include <boost/filesystem.hpp>
int main() {
boost::filesystem::path path("/Users/schoen"); // random pathname
bool result = boost::filesystem::is_directory(path);
printf("Path is a directory : %d\n", result);
return 0;
}
This is just something simple to make sure it is all set up correctly. Of course I tried to compile at this point and it failed. Did some googling and found this site. It said to add the boost library to the linker by going to project properties and adding "boost_filesystem". I tried this, and well it didn't work.
Can someone point me in the right direction or give me a hint to how to set up Boost in an Eclipse project?
I am new to C++ and Eclipse, and most my experience is in Java with Netbeans. So I am pretty lost at the moment.
UPDATE
I just wanted to update on what I have tried based on the answers given.
Based on Alex's suggestion I added boost_system and boost_filesystem to the linker list. I was still getting the same compiler errors.
Following the suggestion from rve I added the path to the boost libraries to the Library search path. When this did not work. I cleared out the linker list and tried it with just the library search path. This also did not work.
I then cleared the Library search path. I then manually edited the command on the linker window to be 'g++ -L/Users/jacobschoen/Library/boost_1_45_0/stage/lib -lboost -lboost_filesystem'. This also did not work.
In all of these I tried setting the path to boost to be '/Users/jacobschoen/Library/boost_1_45_0' and '/Users/jacobschoen/Library/boost_1_45_0/stage/lib'. Neither worked.
As requested the comiler error for the above code is:
**** Build of configuration Debug for project test ****
make all
Building file: ../src/test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test.d" -MT"src/test.d" -o"src/test.o" "../src/test.cpp"
../src/test.cpp:10:32: warning: boost/filesystem.hpp: No such file or directory
../src/test.cpp: In function 'int main()':
../src/test.cpp:13: error: 'boost' has not been declared
../src/test.cpp:13: error: expected `;' before 'path'
../src/test.cpp:14: error: 'boost' has not been declared
../src/test.cpp:14: error: 'path' was not declared in this scope
make: *** [src/test.o] Error 1
If any one has any further suggestions I am still trying.
Second Update
On a suggestion by rholmes I added an include library along with the linker list and library search path. So now the compile error is:
**** Build of configuration Debug for project test ****
make all
Building target: test
Invoking: MacOS X C++ Linker
g++ -L/Users/jacobschoen/Library/boost_1_45_0 -o "test" ./src/test.o -lboost_system -lboost_filesystem
ld: library not found for -lboost_system
collect2: ld returned 1 exit status
make: *** [test] Error 1
Any ideas?
Just wanted to be clear on what actually worked, since it was kinda pieced together from a few answers.
Download the boost files and extract them to where you want to put them.
In your terminal navigate to the directory and run ./bootstrap.sh
When that is done run ./bjam (this takes a while so go smoke and get a cup of coffee)
Open up your eclipse Project and go to Project > Properties > C/C++ Build > Settings
Click on MacOS X C++ Linker > Libraries.
You should see a split window with the top being for 'Libraries (-l)'. In this section add both boost_system and boost_filesystem. In the bottom section it should be for 'Library Search Path (-L)'. Here you want to put the path to the stage/lib directory inside where you extracted the boost download. It should look similar to below:
Click GCC C++ Compiler > Includes. This will be a single pane where it says 'Include Paths (-I)', well I think it is an I as he font is weird and could be a lower case l also. Anyway in that section add the path to where you put boost without the stage/lib part. It should look like below:
Everything should compile now with out a problem, and if you need to use any other boost libraries it should be just a matter of adding it to the linker section where boost_filesystem and boost_system are. Enjoy.
Not sure where you do this in Eclipse these days, but under the include paths for Eclipse should be the path to the main boost directory (/Users/jacobschoen/Library/boost_1_45_0?). The compiler line should have something like the following in it, I would think:
Invoking: GCC C++ Compiler
g++ -I/Users/jacobschoen/Library/boost_1_45_0 -O0 -g3 -Wall -c -fmessage-length=0 -MMD (etc..)
Update: Looking at my system, the linker path on yours might be more appropriately:
-I/Users/jacobschoen/Library/boost_1_45_0/stage/lib
Depending, of course, upon how you've installed and built boost -- this is with my most recent attempt with a full source build. Depending upon how you obtained boost, this may or may not be different. I recently redid the boost on my Mac for 64 bit and haven't had much time to try it yet....
Add boost_system to the linker list, together with boost_filesystem.
I had recently uninstalled the boost rpm and installed Boost like how you did. I had no problems running Boost programs in Eclipse. I didn't add any extra parameters. Just installed boost and ran Boost programs. It works fine.
Tried your program in the vi editor. Commented out everything in main
#include <cstdio>
#include <boost/filesystem.hpp>
int main() {
/*boost::filesystem::path path("/Users/schoen"); // random pathname
bool result = boost::filesystem::is_directory(path);
printf("Path is a directory : %d\n", result);*/
return 0;
}
and it still gave this error:
/tmp/cc7TAIYS.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x29): undefined reference to `boost::system::get_system_category()'
test.cpp:(.text+0x35): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x41): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x4d): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x59): undefined reference to `boost::system::get_system_category()'
collect2: ld returned 1 exit status
I'm puzzled. Boost programs work on my system, but your program's header files itself are giving a problem. I doubt it's a problem with Eclipse. It has to be something else.
I just ran into something very similar to this using eclipse and CDT... It turns out, using ubuntu and apt-get, libboost_system installs as libboost_system.1.40.0 in /usr/lib
If you try to add it via the library tab in Helios it will complain because it is looking for *.so and *.s0.1.40.0 clearly doesn't match that. However after looking closely at what the linker was trying to doo, I just typed the raw string "boost_system" into the include path adder. This resulted in the linker doing a " -lboost_system" which is a format the linker knows how to deal with in resolving version dependency... If you instead put in the full path to the .so file, the linker will just complain because it tries to do a " -l/usr/lib/libboost_system.so.1.40.0" .
So take my advice and just type in the simple " boost_system" after doing an apt-get install.. It will make it all very easy.