User forums > Help
Incorect work with libraries?
Wiz97:
I installed the latest C::B with MinGW/GCC inluded on windows (windows server 2008)
I wanted to use Poco and Boost libraries. Firstly I tried to add Poco libs to my project.
I added Include,Lib dir, added preprocessor definitions.
When I compile simple program:
--- Code: ---#include "Poco/Net/NetworkInterface.h"
#include "Poco/Net/Socket.h"
#include <iostream>
#include <vector>
using Poco::Net::NetworkInterface;
using std::vector;
using std::cout;
using std::endl;
using Poco::Net::Socket;
int main()
{
vector<Poco::Net::NetworkInterface> nil = Poco::Net::NetworkInterface::list();
}
--- End code ---
I got:
Build log:
--- Code: ---E:/c++/Projects/CB1/CBTestMakefile/CppTest.cpp:16: undefined reference to `Poco::Net::NetworkInterface::list()'
obj\Debug\CppTest.o: In function `_ZN9__gnu_cxx13new_allocatorIN4Poco3Net16NetworkInterfaceEE10deallocateEPS3_j':
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/ext/new_allocator.h:(.text$_ZSt8_DestroyIN4Poco3Net16NetworkInterfaceEEvPT_[void std::_Destroy<Poco::Net::NetworkInterface>(Poco::Net::NetworkInterface*)]+0xd): undefined reference to `Poco::Net::NetworkInterface::~NetworkInterface()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 30 seconds)
2 errors, 0 warnings
--- End code ---
Build messages:
--- Code: ---obj\Debug\CppTest.o||In function `main':|
E:\c++\Projects\CB1\CBTestMakefile\CppTest.cpp|16|undefined reference to `Poco::Net::NetworkInterface::list()'|
obj\Debug\CppTest.o||In function `_ZN9__gnu_cxx13new_allocatorIN4Poco3Net16NetworkInterfaceEE10deallocateEPS3_j':|
)]+0xd)||undefined reference to `Poco::Net::NetworkInterface::~NetworkInterface()'|
||=== Build finished: 2 errors, 0 warnings ===|
--- End code ---
Then I wanted to try any other library, like Boost
I folowed steps on http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef
Then I tried to compile such program:
--- Code: ---#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
--- End code ---
And got
Build messages:
--- Code: ---obj\Debug\CppTest.o||In function `_ZN9__gnu_cxxmiIPKcS2_SsEENS_17__normal_iteratorIT_T1_E15difference_typeERKS6_RKNS3_IT0_S5_EE':|
boost::regex_constants::_match_flags)]+0x9a)||undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match()'|
unsigned int)]+0x22)||undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'|
obj\Debug\CppTest.o||In function `main':|
E:\c++\Projects\CB1\CBTestMakefile\CppTest.cpp|6|undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'|
||=== Build finished: 3 errors, 0 warnings ===|
--- End code ---
Looks like "uderfined reference" error caused because headers are found, but libraries object code doesn't include the realisation. And it is the same with Poco and Boost library sets....
What is the reason of such errors and how to fix it?
jfouche:
You have to build those libs, and then add them to the linker :
--- Code: ---project -> Build options
-> linker : Add the libs
-> Search directory -> Linker : Add the libs path
--- End code ---
I don't know POCO, but for boost, you will need to add boost-regexp-mingw-3.4.5.lib (for me)
I suggest you also to create environment variable for those tools :
Settings -> Global variables :
Add new variable named "boost"
--- Code: ---Base : C:\projets\cpp\boost_1_36_0 (for me)
Include : C:\projets\cpp\boost_1_36_0
lib : C:\projets\cpp\boost_1_36_0\bin.v2\libs
--- End code ---
and put $(boost.include) in search directory -> compiler
and $(boost.lib) in search directory -> linker
Use bjam to build boost
HTH
--
Jérémie
Wiz97:
Of course libraries are already built,
Search Directories for Compiler, Linker are set and on Linker settings tab "Link libraries" contains required by headers libs.
I have such kind of errors with everything set up.
My C::B project file:
--- Code: ---<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="CodeBlocksTest" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin\Debug\CodeBlocksTest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj\Debug\" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="$(#boost.include)" />
</Compiler>
<Linker>
<Add library="..\..\boost_1_36_0\lib\boost_regex-vc90-mt-1_36.lib" />
<Add directory="$(#boost.lib)" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin\Release\CodeBlocksTest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj\Release\" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
--- End code ---
Now I changed a bit project (Poco paths added)
Thats a program I try to build:
--- Code: ---#include <boost/regex.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "Poco/Net/NetworkInterface.h"
using Poco::Net::NetworkInterface;
using std::cout;
using std::vector;
using std::endl;
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
vector<NetworkInterface> nil = NetworkInterface::list();
for (NetworkInterface::NetworkInterfaceList::iterator iter = nil.begin();
iter != nil.end(); ++iter)
{
NetworkInterface ni = *iter;
cout << "Network interface: " << ni.name() << endl
<< " Submenet mask:" << ni.subnetMask().toString() << endl
<< " Broadcast: " << ni.broadcastAddress().toString() << endl
<< " Address: " << ni.address().toString() << endl
<< endl;
}
}
--- End code ---
Thats full command line info (all params suplied to compiler - paths too, are here):
--- Code: ----------------- Build: Debug in CodeBlocksTest ---------------
[ 50.0%] mingw32-g++.exe -Wall -fexceptions -DPOCO_STATIC -g -IC:\boost_1_36_0\include\boost-1_36 -IC:\poco\svn\Foundation\include -IC:\poco\svn\Net\include -c C:\Projects\CodeBlocksTest\main.cpp -o obj\Debug\main.o
[100.0%] mingw32-g++.exe -LC:\boost_1_36_0\lib -LC:\poco\svn\lib -o bin\Debug\CodeBlocksTest.exe obj\Debug\main.o C:\boost_1_36_0\lib\boost_regex-vc90-mt-1_36.lib C:\poco\svn\lib\PocoFoundationmtd.lib C:\poco\svn\lib\PocoNetmtd.lib
obj\Debug\main.o: In function `main':
C:/Projects/CodeBlocksTest/main.cpp:27: undefined reference to `Poco::Net::NetworkInterface::list()'
C:/Projects/CodeBlocksTest/main.cpp:31: undefined reference to `Poco::Net::NetworkInterface::NetworkInterface(Poco::Net::NetworkInterface const&)'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::NetworkInterface::address() const'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::IPAddress::toString() const'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::NetworkInterface::broadcastAddress() const'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::IPAddress::toString() const'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::NetworkInterface::subnetMask() const'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::IPAddress::toString() const'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::NetworkInterface::name() const'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::NetworkInterface::~NetworkInterface()'
C:/Projects/CodeBlocksTest/main.cpp:32: undefined reference to `Poco::Net::NetworkInterface::~NetworkInterface()'
obj\Debug\main.o: In function `ZN9__gnu_cxxmiIPKcS2_SsEENS_17__normal_iteratorIT_T1_E15difference_typeERKS6_RKNS3_IT0_S5_EE':
C:/boost_1_36_0/include/boost-1_36/boost/regex/v4/basic_regex.hpp:(.text$_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[bool boost::regex_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)]+0x9a): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match()'
C:/boost_1_36_0/include/boost-1_36/boost/regex/v4/basic_regex.hpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)]+0x22): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
obj\Debug\main.o: In function `main':
C:/Projects/CodeBlocksTest/main.cpp:13: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
obj\Debug\main.o: In function `ZN9__gnu_cxxmiIPKcS2_SsEENS_17__normal_iteratorIT_T1_E15difference_typeERKS6_RKNS3_IT0_S5_EE':
C:/boost_1_36_0/include/boost-1_36/boost/regex/v4/basic_regex.hpp:(.text$_ZSt8_DestroyIN4Poco3Net16NetworkInterfaceEEvPT_[void std::_Destroy<Poco::Net::NetworkInterface>(Poco::Net::NetworkInterface*)]+0xd): undefined reference to `Poco::Net::NetworkInterface::~NetworkInterface()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 3 seconds)
15 errors, 0 warnings
--- End code ---
TDragon:
--- Quote from: Wiz97 on September 16, 2008, 10:38:13 pm ---
--- Code: ---[100.0%] mingw32-g++.exe <...> C:\boost_1_36_0\lib\boost_regex-vc90-mt-1_36.lib <...>
--- End code ---
--- End quote ---
This is wrong. You're using MinGW; you need to link with the MinGW version of a library, not the Visual C++ version.
MortenMacFly:
--- Quote from: TDragon on September 17, 2008, 01:34:59 am ---This is wrong. You're using MinGW; you need to link with the MinGW version of a library, not the Visual C++ version.
--- End quote ---
Just for the record: If you compile boost in this version with MinGW/GCC it will create *.lib files (*not* *.a files). So (s)he might in fact be using the MinGW/GCC variant correctly. This already lead to confusion in another thread in our forum. Maybe a search will help...?!
BTW: I just renamed the files to *.a in my copy.
Navigation
[0] Message Index
[#] Next page
Go to full version