Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
cmake, c++ question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Treborius
Guru
Guru


Joined: 18 Oct 2005
Posts: 540
Location: Berlin

PostPosted: Thu Aug 30, 2007 11:53 am    Post subject: cmake, c++ question Reply with quote

i am working on a little program with cmake,
i use the cmake command

ADD_LIBRARY
(functions
class1.hpp class1.cpp
class2.hpp class2.cpp
class3.hpp class3.cpp
)

to a build a static library and then link eveything to the main-program

everything worked great, till now,
i tried to add a hpp + a cpp with some general-functions to the library
Code:

functions.hpp functions.cpp to the library,


the functions are something like
Code:

void Tokenize(const std::string& str, std::vector<std::string>& out);


but now i get undefined references to these functions when i try to build my program,
if i encapsulate these functions into a class, everything works fine

does anybody know where these problems come from?
Back to top
View user's profile Send private message
didl
Retired Dev
Retired Dev


Joined: 09 Sep 2003
Posts: 1106
Location: Pittsburgh, PA

PostPosted: Thu Aug 30, 2007 1:00 pm    Post subject: Reply with quote

Could you please post the cmake output for compiling the static lib
and linking as well as the error message. Depending on
your setup you may need to do
Code:

VERBOSE=true make

to obtain full output.
Back to top
View user's profile Send private message
Treborius
Guru
Guru


Joined: 18 Oct 2005
Posts: 540
Location: Berlin

PostPosted: Thu Aug 30, 2007 4:17 pm    Post subject: Reply with quote

before i tried to move my functions out of the header into to cpp and so into the lib, everything went fine, then i splitted my methods.hpp
wich looked like that :
[/code]
void Tokenize(const std::string& str,
std::vector<std::string>& tokens,
const std::string& delimiter = " ")
{
tokens.clear();
// Skip delimiters at beginning.
.
.
.
}
[/code]
into methods.hpp
Code:

void Tokenize(const std::string& str,
                      std::vector<std::string>& tokens,
                      const std::string& delimiter = " ");


and cpp
Code:

void Tokenize(const std::string& str,
                      std::vector<std::string>& tokens,
                      const std::string& delimiter)
{
tokens.clear();
// Skip delimiters at beginning
.
.
.
}


this is the cmake output of building the static lib, where the methods.cpp and the hpp are in
Code:

[ 30%] Building CXX object lib_functions/CMakeFiles/functions.dir/methods.o
/usr/bin/c++   -I/home/henning/fngpr_08/scm/EARS/lib -Wall -Weffc++ -Wno-pragmas -g -O0 -pedantic -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wconversion -Wreorder -o lib_functions/CMakeFiles/functions.dir/methods.o -c methods.cpp
/public/bin/cmake -E cmake_progress_report /home/henning/fngpr_08/scm/EARS/CMakeFiles 9


and thats the error when i try to link against this lib
Code:

Linking CXX executable ../bin/test_data
./train_data/libtraindata.a(traindatabase.o): In function `TrainDataBase':
./train_data/traindatabase.cpp:45: undefined reference to `Tokenize(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
./train_data/traindatabase.cpp:45: undefined reference to `Tokenize(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
./train_data/libtraindata.a(dataset.o): In function `DataSet::parse_lab_file()':
./train_data/dataset.cpp:77: undefined reference to `Tokenize(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: ld returned 1 exit status
make[2]: *** [test/../bin/test_data] Error 1
make[1]: *** [test/CMakeFiles/../bin/test_data.dir/all] Error 2
make: *** [all] Error 2


and thats how i try to link against the lib
Code:

ADD_EXECUTABLE(../bin/test_data test_data_base.cpp)
target_link_libraries(../bin/test_data
            functions
            math
            traindata
            )
Back to top
View user's profile Send private message
didl
Retired Dev
Retired Dev


Joined: 09 Sep 2003
Posts: 1106
Location: Pittsburgh, PA

PostPosted: Fri Aug 31, 2007 1:02 pm    Post subject: Reply with quote

It is hard to tell from what you posted where the problem lies.
Can you make sure that methods.o is part of the library via
"ar -t"?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum