[C++-sig] unresolved symbols

John Holland john at holj.de
Fri Apr 18 11:12:54 CEST 2003


hi there,

i'm new to boost and extending python.

i'm trying to write a boost-python module. it currently contains three files: 
module header, module boost definition and a class definition.

this module is currently being built outside the boost build directory 
structure. i've copied the files Jamfile, Jamrule and boost-build.jam from 
the examples directory and altered them to reflect my build directory 
structure.

the entire module has been held as basic as possible. the module 
implementation file is as follows:

##################################################################
##################################################################
##################################################################
// boost.cpp

#include <string>

#include <logger.hpp>
#include <boost/python.hpp>

namespace py = boost::python;
using namespace logger;
using namespace py;

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(log_overloads, Client::log, 1, 2)

BOOST_PYTHON_MODULE(logger)
{
   class_<Client>("Client", init<std::string&>())
      .def("__call__", &Client::log, log_overloads())
      .add_property("source", &Client::getSource)
      .add_property("level", &Client::getLevel, &Client::setLevel)
   ;

   enum_<LogLevel>("level")
      .value("debug",    debug)
      .value("test",     test)
      .value("review",   review)
      .value("warning",  warning)
      .value("error",    error)#ifndef __logger_hpp__
      .value("critical", critical)
      .value("fatal",    fatal)
   ;
}

##################################################################
##################################################################
##################################################################

the module header and class implementation are equally simple:

##################################################################
##################################################################
##################################################################
// logger.hpp

#ifndef __logger_hpp__
#define __logger_hpp__

#include <string>

namespace logger
{

// defines all basic log levels known to this module
enum LogLevel
{
   all      = 1 << 31,
   debug    = 1 << 31,

   test     = 1 << 21,

   review   = 1 << 16,

   info     = 1 << 11,

   warning  = 1 << 4,
   error    = 1 << 3,
   critical = 1 << 2,
   fatal    = 1 << 1,
   off      = 1 << 0,
   none     = -1
};                                     // enum LogLevel

/******************************************************************************
 *
 *
 *
 */
class Client
{
public:
   Client (std::string& name);

   ~Client (void);

   std::string getSource (void) { return source; }

   LogLevel setLevel (const LogLevel level);
   LogLevel getLevel (void) { return this->level; }

   int log (const std::string& message, const LogLevel locallevel = none);

protected:

private:
   std::string source;
   LogLevel level;
};                                     // class Client

};                                     // namespace logger

#endif                                 // __logger_hpp__

##################################################################
##################################################################
##################################################################
// Client.cpp

#include <iostream>
#include <string>

#include <logger.hpp>

using namespace logger;

Client::Client (std::string& name)
{
   this->source = name;
   this->level  = none;
}

LogLevel
Client::setLevel (const LogLevel newlevel)
{
   if (none == newlevel)
   {
      return none;
   }
   return this->level = newlevel;
}

int
Client::log (const std::string& message, const LogLevel level)
{
   LogLevel localLevel = (none == level) ? level : this->level;

   std::cout << ":" << localLevel << ":" << message;
   return 1;
}

##################################################################
##################################################################
##################################################################

using bjam the module complies w/o warnings or errors. however, while 
importing the newly generated python module the interpreter spits out an 
unresolved symbols error message:

Python 2.2.1 (#1, Sep 10 2002, 17:49:17)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logger
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: 
/home/jh/Projects/boost/src/logger/bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/logger.so: 
undefined symbol: _ZN6logger6ClientD1Ev
>>>



the bjam verbose output is:


gcc-C++-action 
bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/logger.o

    g++  -c -Wall -ftemplate-depth-100  -DNDEBUG -DBOOST_PYTHON_DYNAMIC_LIB  
-O3 -finline-functions -Wno-inline -fPIC   -I"."  -I "/usr/include/python2.2" 
-I "/usr/local"  -o 
"bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/logger.o"  
"logger.cpp"

gcc-C++-action 
bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/LogClient.o

    g++  -c -Wall -ftemplate-depth-100  -DNDEBUG -DBOOST_PYTHON_DYNAMIC_LIB  
-O3 -finline-functions -Wno-inline -fPIC   -I"."  -I "/usr/include/python2.2" 
-I "/usr/local"  -o 
"bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/LogClient.o"  
"LogClient.cpp"

gcc-Link-action 
bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/logger.so

    LD_LIBRARY_PATH=:/usr/lib/python2.2/config
    export LD_LIBRARY_PATH
    g++   -s -fPIC -shared  -o 
"bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/logger.so"  
-L"" -L"/usr/lib/python2.2/config"   
"bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/logger.o" 
"bin/logger.so/gcc/release/runtime-link-dynamic/shared-linkable-true/LogClient.o"     
-lboost_python  -Wl,-rpath-link,.



and the g++ version is:



#g++ --version
g++ (GCC) 3.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.





could someone be so kind as to help me resolve this problem?





thanx in advance,


John Holland

john at holj.de








More information about the Cplusplus-sig mailing list