I try to write a simple login script using bcrypt. I've tried to use the C wrapper libbcrypt library - https://github.com/trusch/libbcrypt - but got stuck with the compiler complaining about undefined references to bcrypt_checkpw, bcrypt_hashpw, bcrypt_gensalt in the BCrypt class.
First thing I've done was to follow the instructions from the readme.md - https://github.com/trusch/libbcrypt/blob/master/README.md :
git clone https://github.com/trusch/libbcrypt
cd libbcrypt
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig
Then I have my main.cpp file
#include <iostream>
#include "User_Class.hpp"
void checkPermission();
int main(int argc, char* argv[]) {
checkPermission();
return 0;
}
void checkPermission() {
User_Class User;
User.Login("test");
}
My User_Class.cpp file
#include <iostream>
#include "Password_Class.hpp"
#include "User_Class.hpp"
bool User_Class::Login(std::string password) {
return Password_Class::authenticate(password);
}
My User_Class.hpp file
class User_Class {
public:
bool Login(std::string password);
};
My Password_Class.cpp file
#include <iostream>
#include "Password_Class.hpp"
#include "bcrypt/BCrypt.hpp"
bool Password_Class::authenticate(std::string password) {
// this fails!
std::string hash = BCrypt::generateHash(password);
std::cout << BCrypt::validatePassword(password,hash) << std::endl;
return true;
}
And my Password_Class.hpp file
class Password_Class {
public:
static bool authenticate(Glib::ustring password);
};
When compiling with this command
g++ -lbcrypt main.cpp User_Class.cpp Password_Class.cpp -o main `pkg-config --libs --cflags gtkmm-3.0`
I get errors
/tmp/ccc3Va1h.o: In Funktion »BCrypt::generateHash(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)«:
Password_Class.cpp:(.text._ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[_ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0x44): Warnung: undefinierter Verweis auf »bcrypt_gensalt«
Password_Class.cpp:(.text._ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[_ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0xb0): Warnung: undefinierter Verweis auf »bcrypt_hashpw«
/tmp/ccc3Va1h.o: In Funktion »BCrypt::validatePassword(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)«:
Password_Class.cpp:(.text._ZN6BCrypt16validatePasswordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_[_ZN6BCrypt16validatePasswordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_]+0x33): Warnung: undefinierter Verweis auf »bcrypt_checkpw«
collect2: error: ld returned 1 exit status
So please can someone tell me what's going on here? What have I done wrong so how do I use bcrypt in C++? I guess some libraries couldn't be found but I'm really no expert in linux or C++ so please forgive me ;)
Thank you for your help!
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 2 years ago.
I am learning C++ and stuck with what seems to be a super simple thing. :-(
Here is my Person.h
#include <string>
class Person {
private:
std::string firstName;
std::string lastName;
int arbitaryNumber;
public:
Person(std::string firstName, std::string lastName, int arbitaryNumber);
std::string getName();
};
My CPP file is:
#include "Person.h"
Person::Person(std::string firstName, std::string lastName, int arbitaryNumber):
firstName(firstName), lastName(lastName), arbitaryNumber(arbitaryNumber) {
}
std::string Person::getName() {
return this->firstName + " " + this->lastName;
}
So far things are super simple. Let's used it in the main.
#include <iostream>
# include "Person.h"
int main(int argc, char **argv) {
Person p("Nawa", "Man", 100);
return 0;
}
When I compile/run my code, I got this error.
Building in: /Users/nawa/eclipse-workspace-CPP/ExampleMake/build/default
make -f ../../Makefile
g++ -c -O2 -o ExampleMake.o /Users/nawa/eclipse-workspace-CPP/ExampleMake/ExampleMake.cpp
g++ -o ExampleMake ExampleMake.o
Undefined symbols for architecture x86_64:
"Person::Person(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, int)", referenced from:
_main in ExampleMake.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ExampleMake] Error 1
Build complete (2 errors, 0 warnings): /Users/nawa/eclipse-workspace-
CPP/ExampleMake/build/default
What is wrong with the constructor? I am using Eclipse on Mac.
I suspected that it has something to do with string literal and str::string but I am not sure. So, when I compiled it in the command line, I got the same error so this does not seems to be Eclipse problem.
Please help.
Thanks.
g++ -o ExampleMake ExampleMake.o
You are linking just one file, when you have 2 cpp files.
I am writing code using C++ boost library, I am getting a linking error -
Code
#include "test/support/checkers/log-entry-presence-checkers.h"
#include <sstream>
#include <iostream>
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
using namespace std;
namespace YumaTest
{
LogEntryPresenceChecker::LogEntryPresenceChecker(
const vector<string>& expPresentText )
: checkStrings_( expPresentText )
{
}
LogEntryPresenceChecker::~LogEntryPresenceChecker()
{
}
void LogEntryPresenceChecker::operator()( const string& logFilePath ) const
{
ifstream logFile;
string line;
bool entryFound;
BOOST_FOREACH ( const string& val, checkStrings_ )
{
entryFound = false;
BOOST_TEST_MESSAGE( "\tChecking " << val << " is present" );
logFile.open( logFilePath );
if (logFile.is_open()) {
while ( logFile.good() && entryFound == false ) {
getline(logFile, line);
if ( line.find( val ) != string::npos ) {
entryFound = true;
}
}
logFile.close();
}
BOOST_CHECK_EQUAL( true, entryFound );
}
}
Linking Error -
g++ output/b64.o output/bobhash.o output/cap.o output/cfg.o output/cli.o output/conf.o output/def_reg.o output/dlq.o output/ext.o output/grp.o output/help.o output/json_wr.o output/log.o output/ncx_appinfo.o output/ncx.o output/ncx_feature.o output/ncx_list.o output/ncxmod.o output/ncx_num.o output/ncx_str.o output/obj.o output/obj_help.o output/op.o output/plock.o output/plock_cb.o output/rpc.o output/rpc_err.o output/runstack.o output/ses.o output/ses_msg.o output/status.o output/tk.o output/top.o output/tstamp.o output/typ.o output/val.o output/val_util.o output/var.o output/xml_msg.o output/xmlns.o output/xml_util.o output/xml_val.o output/xml_wr.o output/xpath1.o output/xpath.o output/xpath_wr.o output/xpath_yang.o output/yang.o output/yang_ext.o output/yang_grp.o output/yang_obj.o output/yang_parse.o output/yang_typ.o output/yin.o output/yinyang.o output/send_buff.o output/agt_acm.o output/agt.o output/agt_cap.o output/agt_cb.o output/agt_cfg.o output/agt_cli.o output/agt_commit_complete.o output/agt_connect.o output/agt_hello.o output/agt_if.o output/agt_ncx.o output/agt_not.o output/agt_plock.o output/agt_proc.o output/agt_rpc.o output/agt_rpcerr.o output/agt_ses.o output/agt_signal.o output/agt_state.o output/agt_sys.o output/agt_time_filter.o output/agt_timer.o output/agt_top.o output/agt_tree.o output/agt_util.o output/agt_val.o output/agt_val_parse.o output/agt_xml.o output/agt_xpath.o output/agt_yuma_arp.o output/agt_ncxserver.o output/checker-group.o output/string-presence-checkers.o output/log-entry-presence-checkers.o output/sil-callback-log.o output/callback-checker.o output/sil-callback-controller.o output/device-test-db.o output/device-test-db-debug.o output/state-data-test-db.o output/abstract-nc-session.o output/nc-base-query-test-engine.o output/nc-default-operation-config.o output/nc-query-test-engine.o output/nc-query-utils.o output/nc-strings.o output/yuma-op-policies.o output/abstract-global-fixture.o output/test-context.o output/base-suite-fixture.o output/query-suite-fixture.o output/simple-container-module-fixture.o output/simple-yang-fixture.o output/device-module-fixture.o output/device-get-module-fixture.o output/device-module-common-fixture.o output/state-get-module-fixture.o output/state-data-module-common-fixture.o output/cpp-unit-op-formatter.o output/log-utils.o output/ptree-utils.o output/base64.o output/NCMessageBuilder.o output/xpo-query-builder.o output/state-data-query-builder.o output/spoof-nc-session.o output/spoof-nc-session-factory.o output/running-cb-checker.o output/candidate-cb-checker.o output/integ-cb-checker-factory.o output/integ-fixture-helper.o output/integ-fixture-helper-factory.o output/simple-edit-tests.o output/default-none-tests.o output/simple-edit-running.o -Wall -g -lxml2 -lboost_unit_test_framework -Wl,--export-dynamic -o test-simple-edit-running
output/log-entry-presence-checkers.o: In function `YumaTest::LogEntryPresenceChecker::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/checkers/log-entry-presence-checkers.cpp:52: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/log-entry-presence-checkers.o: In function `YumaTest::LogEntryNonPresenceChecker::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/checkers/log-entry-presence-checkers.cpp:89: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/abstract-nc-session.o: In function `YumaTest::AbstractNCSession::concatenateLogFiles()':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/nc-session/abstract-nc-session.cpp:66: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/abstract-nc-session.o: In function `YumaTest::AbstractNCSession::appendLog(std::basic_ofstream<char, std::char_traits<char> >&, unsigned short)':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/nc-session/abstract-nc-session.cpp:84: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
collect2: ld returned 1 exit status
I am not getting why there is a error of undefined reference.
Please help me out How can I get rid of this issue.
Thanks in Advance.
Did you copy/paste the object files or library files from somewhere? They must be built against the same binary interface.
This looks very much like you're using C++11 headers but a C++03 runtime, because your compiled code expects to find ifstream constructor overloads taking std::string (introduced in C++11), but the linker can find no evidence of implementation for such overloads.
Rebuild everything, including your Boost library, with the same toolchain and see what happens.
I have looked all over Stack Overflow and other websites about this famous error, and all of them are very specific, and in my case I cannot find a solution. I am making an ncurses application and when i try to compile it, it causes the following error:
Undefined symbols for architecture x86_64:
"NCRS::End()", referenced from:
_main in crspro-85eaaf.o
"NCRS::Start()", referenced from:
_main in crspro-85eaaf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I compile the code with the following line:
$ clang++ crspro.cpp -lncurses -o crspro
Here is the code:
crspro.cpp
#include "ncrs.h"
int main(int argc, char* argv[]) {
NCRS::Start();
getch();
NCRS::End();
return 0;
}
ncrs.h
#ifndef NCRS_H
#define NCRS_H
#include <ncurses.h>
#include <string>
typedef std::string string;
class NCRS {
private:
static bool __curses_on;
static bool __buffer;
static bool __echo;
static bool __keypad;
public:
static void Start(bool bbuffer=false, bool becho=false, bool bkeypad=false);
static void End();
};
#endif
ncrs.cpp
#include "ncrs.h"
static void NCRS::Start(bool bbuffer=false, bool becho=false, bool bkeypad=false) {
initscr();
if (bbuffer) raw();
if (becho) echo(); else noecho();
if (bkeypad) keypad(stdscr, TRUE); else keypad(stdscr, FALSE);
__buffer = bbuffer;
__echo = becho;
__keypad = bkeypad;
__curses_on = true;
}
static void NCRS::End() { nocbreak(); echo(); keypad(stdscr, FALSE); endwin(); }
I don't have any issues in the code itself as far as I can tell. I have tried even including ncrs.cpp (The horror!!) but I still get the same problems.
Can anyone help with this issue? I've had this problem before with other projects and I've had to abandon them because I couldn't find a solution.
Thanks to anyone who can help!
_
_
EDIT
compile with:
clang++ crspro.cpp ncrs.cpp -lncurses -o crspro
returns error:
Undefined symbols for architecture x86_64:
"NCRS::__curses_on", referenced from:
NCRS::Start(bool, bool, bool) in ncrs-e52041.o
"NCRS::__echo", referenced from:
NCRS::Start(bool, bool, bool) in ncrs-e52041.o
"NCRS::__buffer", referenced from:
NCRS::Start(bool, bool, bool) in ncrs-e52041.o
"NCRS::__keypad", referenced from:
NCRS::Start(bool, bool, bool) in ncrs-e52041.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Your compilation isn't including anything from ncrs.cpp, which is where both NCRS::Start() and NCRS::End() are defined. You probably want
clang++ crspro.cpp ncrs.cpp -lncurses -o crspro
Or if you want to build the object files separately and then link them:
clang++ -c crspro.cpp -c
clang++ -c ncrs.cpp -c
clang++ crspro.o ncrs.o -lncurses -o crspro
Your next error about "NCRS::__curses_on" is because you're using static variables without defining them you need to add
bool NCRS::__curses_on=false;
bool NCRS::__buffer=false;
bool NCRS::__echo=false;
bool NCRS::__keypad=false;
to one of your .cpp files. (presumably ncrs.cpp is the logical place.)
It's probably worth thinking about whether they should be static (and whether the functions should be static too) - they may need to be, but static class variables are essentially global variables, which will often come back to bite you later. They make it harder to understand the flow of the code, and can make multi-threading and testing painful.
I have install leveldb in my home directory ~/local like this.
[~/temp/leveldb-1.15.0] $ make
[~/temp/leveldb-1.15.0] $ cp -av libleveldb.* $HOME/local/lib/
[~/temp/leveldb-1.15.0] $ cp -av include/leveldb $HOME/local/include/
My c++ program like this:
#include <assert.h>
#include <iostream>
#include "leveldb/db.h"
using namespace std;
int main(int argc,char * argv[])
{
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
std::string dbpath = "tdb";
leveldb::Status status = leveldb::DB::Open(options, dbpath, &db);
assert(status.ok());
std::string key1 = "grz";
std::string key2 = "grz-rt#63.com";
cout<<"Open db OK"<<std::endl;
std::string value;
leveldb::Status s ;
s = db->Put(leveldb::WriteOptions(), key1, key2);/*key1和key2作为一对key-value对插入*/
s = db->Get(leveldb::ReadOptions(), key1, &value);/*根据key返回对应的value值*/
cout<<value<<std::endl;
delete db;/*删除数据库*/
return 0;
}
I compile this C++ program like this:
g++ -o Main Main.cpp ~/local/lib/libleveldb.a -lpthread -I ~/local/include/
But I get the error like this:
/public/home/kli/local/lib/libleveldb.a(table_builder.o): In function `leveldb::TableBuilder::WriteBlock(leveldb::BlockBuilder*, leveldb::BlockHandle*)':
table_builder.cc:(.text+0x678): undefined reference to `snappy::MaxCompressedLength(unsigned long)'
table_builder.cc:(.text+0x6b2): undefined reference to `snappy::RawCompress(char const*, unsigned long, char*, unsigned long*)'
/public/home/kli/local/lib/libleveldb.a(format.o): In function `leveldb::ReadBlock(leveldb::RandomAccessFile*, leveldb::ReadOptions const&, leveldb::BlockHandle const&, leveldb::BlockContents*)':
format.cc:(.text+0x5de): undefined reference to `snappy::GetUncompressedLength(char const*, unsigned long, unsigned long*)'
format.cc:(.text+0x64e): undefined reference to `snappy::RawUncompress(char const*, unsigned long, char*)'
collect2: ld returned 1 exit status
I don't know what's wrong.
I am new to Linux. Thank you very much!
libleveldb.a misses Snappy when being linked which would be probably in libsnappy.a in the same directory.
Looks like the Makefile is incomplete.
With the current install, you need to edit the Makefile to link against snappy and to include -L/usr/local/lib instead of -L/usr/local/include.
(Will post pull request later)
I'm attempting to write a program using a genetic algorithm which is a particular type of optimization algorithm. I found a free library for this task called "Evolutionary Objects" and implemented a very simple genetic algorithm instance. The program code, the build commands that netbeans implements, and finally the error messages that I receive are posted below in separate blocks. If you allow me your help, you'll see that something is going wrong with the cout function. When I searched the internet for similar difficulties, I found that people had been correcting the problem by simply using g++ rather than gcc yet I am already using g++, as you can see. Any help would be appreciated....
The program code is immediately below:
#include <stdexcept>
#include <iostream>
#include <eo>
#include <ga.h>
typedef eoBit<double> Indi;
double binary_value(const Indi & _indi)
{
double sum = 0;
for (unsigned i = 0; i < _indi.size(); i++)
sum += _indi[i];
return sum;
}
void main_function(int argc, char **argv)
{
const unsigned int SEED = 42; // seed for random number generator
const unsigned int T_SIZE = 3; // size for tournament selection
const unsigned int VEC_SIZE = 16; // Number of bits in genotypes
const unsigned int POP_SIZE = 100; // Size of population
const unsigned int MAX_GEN = 400; // Maximum number of generation before STOP
const float CROSS_RATE = 0.8; // Crossover rate
const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
const float MUT_RATE = 1.0; // mutation rate
rng.reseed(SEED);
eoEvalFuncPtr<Indi> eval( binary_value );
eoPop<Indi> pop;
for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)
{
Indi v; // void individual, to be filled
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
{
bool r = rng.flip(); // new value, random in {0,1}
v.push_back(r); // append that random value to v
}
eval(v); // evaluate it
pop.push_back(v); // and put it in the population
}
pop.sort();
cout << "Initial Population" << endl;
cout << pop;
eoDetTournamentSelect<Indi> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
eo1PtBitXover<Indi> xover;
eoBitMutation<Indi> mutation(P_MUT_PER_BIT);
eoGenContinue<Indi> continuator(MAX_GEN);
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE, eval, continuator);
gga(pop);
pop.sort();
cout << "FINAL Population\n" << pop << endl;
}
int main(int argc, char **argv)
{
main_function(argc, argv);
return 1;
}
}
Netbeans shows me that it is doing this when attempting build:
make[1]: Entering directory `/home/gregemerson/EO_GA/EO_GA'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux-x86/eo_ga
make[1]: Leaving directory `/home/gregemerson/EO_GA/EO_GA'
CLEAN SUCCESSFUL (total time: 94ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/gregemerson/EO_GA/EO_GA'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/eo_ga
make[2]: Entering directory `/home/gregemerson/EO_GA/EO_GA'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -I../../EO/EO/eo/src -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/eo_ga build/Debug/GNU-Linux-x86/main.o -L../../EO/EO/eo/build/lib /home/gregemerson/EO/EO/eo/build/lib/libcma.a /home/gregemerson/EO/EO/eo/build/lib/libeoutils.a /home/gregemerson/EO/EO/eo/build/lib/libes.a /home/gregemerson/EO/EO/eo/build/lib/libga.a
The error messages are immediately below:
/home/gregemerson/EO_GA/EO_GA/main.cpp:94: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
/home/gregemerson/EO_GA/EO_GA/main.cpp:99: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
/home/gregemerson/EO_GA/EO_GA/main.cpp:149: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
build/Debug/GNU-Linux-x86/main.o: In function `eoPop<eoBit<double> >::sortedPrintOn(std::basic_ostream<char, std::char_traits<char> >&) const':
/home/gregemerson/EO_GA/EO_GA/../../EO/EO/eo/src/eoPop.h:294: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
build/Debug/GNU-Linux-x86/main.o: In function `std::ostream_iterator<eoBit<double>, char, std::char_traits<char> >::operator=(eoBit<double> const&)':
/usr/include/c++/4.6/bits/stream_iterator.h:198: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/eo_ga] Error 1
make[2]: Leaving directory `/home/gregemerson/EO_GA/EO_GA'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/gregemerson/EO_GA/EO_GA'
make: *** [.build-impl] Error 2
Your response did correct for my cout(pop) problem. However, I'm now seeing similar errors in a headers for one of the static libraries that I'm using along with what looks to be related to one of the basic c++ libraries. I get the following. Does this make sense to you?
build/Debug/GNU-Linux-x86/main.o: In function `std::ostream_iterator<eoBit<double>, char, std::char_traits<char> >::operator=(eoBit<double> const&)':
/usr/include/c++/4.6/bits/stream_iterator.h:198: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
build/Debug/GNU-Linux-x86/main.o: In function `eoPop<eoBit<double> >::sortedPrintOn(std::basic_ostream<char, std::char_traits<char> >&) const':
/home/gregemerson/EO_GA/EO_GA/../../EO/EO/eo/src/eoPop.h:294: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
The issue is (for example) here:
cout << pop;
The error,
/home/gregemerson/EO_GA/EO_GA/main.cpp:94: undefined reference to
`operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
Means that there is no basic function that knows how to push an eoPrintable object into an ostream.
Based on the link provided in the comments, this eoPop class has defined a few methods for printing: sortedPrintOn and printOn.
In order to use one of them to print to cout, you would do the following:
pop.printOn(cout); //or pop.printOn(std::cout) if you remove using namespace std;
pop.printSortedOn(cout);
Many peoples are experiencing this problem when they try to use EO C++ lib for first time. I also faced this problem and were able to find the solution. The problem is that the linker does not find the static libraries that have to be linked while building the EO programs. I am now able to successfully compile and use the first tutorial i.e. FirstBitGA.cpp & FirstRealGA.cpp with EO-1.3.1 on Ubunut 10.04 (LTS).
Note: I am writing the complete steps starting from installation, so be patient. Also replace the word 'username' with your user account.
<< Solution >>
Download EO Lib from http://sourceforge.net/projects/eodev/files/latest/download?source=files
Create a directory named EO; I create it in /home/username/ .
Copy the EO Zip file to /home/username/EO and uncompressed it. This will create another directory named 'eo' under /home/username/EO.
Now build the installation files by running the build script in /home/username/EO/eo/build_gcc_linux_release in terminal.
The build script in step-4 will create a directory named 'release' under /home/username/EO/eo. In the release directory the 'lib' folder contains the libraries that have to be linked while compiling any EO program.
Now two paths have to be provided to the compiler for successful compilation:
6.1. The path to include files as a command line argument to g++ i.e. -I /home/username/EO/eo/src < OR > If you are using Qt creator IDE then enter the line ' INCLUDEPATH += /home/username/EO/eo/src' in the .pro file of the probject.
6.2. The path to all link libraries with -L argument to g++ i.e.
-L/home/username/EO/eo/release/lib/libcma.a /home/username/EO/eo/release/lib/libeo.a /home/username/EO/eo/release/lib/libeoserial/home/username/EO/eo/release/lib/libeoutils.a /home/username/EO/eo/release/lib/libes.a /home/username/EO/eo/release/lib/libga.a
For Qt Creator users, enter the following lines into .pro file,
LIBS += -L/home/username/EO/eo/release/lib/libcma.a /home/username/EO/eo/release/lib/libeo.a /home/username/EO/eo/release/lib/libeoserial.a /home/username/EO/eo/release/lib/libeoutils.a /home/username/EO/eo/release/lib/libes.a /home/username/EO/eo/release/lib/libga.a
Enjoy