Wie verwende ich eine Bibliothek in mehreren Klassen, w/o Erhielt "Mehrfachdefinitionsfehler"

StackOverflow https://stackoverflow.com/questions/8855259

  •  28-10-2019
  •  | 
  •  

Frage

Ich beginne ein neues C ++ - Projekt und möchte Boost.build / bjam verwenden.

Ich erhalte "multiple Definitionsfehler", weil, wie ich denke, die Jam -Datei nicht richtig geschrieben ist oder ich die Header nicht richtig einbeziehe oder die Bibliothek vielleicht nicht gut geschrieben habe, was ich nicht untersucht habe.

Main.cpp verwendet Liba. rest.cpp verwendet liba.

Liba ist eine Headerbibliothek. Daher muss ich Header für LIBA sowohl in Main.cpp als auch in Rest.cpp des Compilers über Namespaces usw. beschweren.

Ich benutze GCC auf Debian.

Hier sind meine Jam -Dateien:

Jamroot.jam

import os ;
import modules ;

path-constant boost-root : "/home/dude/include/boost_1_48_0" ;
path-constant cgi-root : "/home/dude/include/cgi-0.7.1/libs/cgi/build" ;
path-constant BOOST_BUILD_PATH : "$(boost-root)/tools/build/v2" ;

# path-constant include-dir : /usr/local/include ;

use-project /boost/ : $(boost-root) ;
use-project /boost/cgi/ : $(cgi-root) ;

lib libsoci_core : : <file>/usr/local/lib/libsoci_core.so ;
lib libsoci_odbc : : <file>/usr/local/lib/libsoci_odbc.so ;
lib libboost_log : : <file>/usr/local/lib/libboost_log.so ;

Jamfile.jam

project hello_fcgi
: requirements
    <library>/boost/cgi/
    <library>/boost/system/
    <library>/boost/thread/
    <include>/usr/local/include/soci/
    <include>/usr/local/include/soci/odbc/
  ;

# exe rest : rest.cpp hello /boost/regex/ libboost_log libsoci_core libsoci_odbc ;
exe hello : main.cpp rest.cpp cms.cpp /boost/regex/ libboost_log libsoci_core libsoci_odbc ;

# Our install rule (builds binaries and copies them to <location>)
install install
 :
   hello
 :
   <location>/var/www/localhost/cgi-bin/
 ;

# Only install example if you use `bjam install' or equivalent
explicit install ;

Die Fehler, die ich bekomme, sind Wiederholungen von:

Performing configuration checks

    - has_icu builds           : yes
...patience...
...patience...
...found 3228 targets...
...updating 1 target...
gcc.link bin/gcc-4.4.5/debug/hello
bin/gcc-4.4.5/debug/rest.o: In function `basic_client':
/usr/include/c++/4.4/exception:62: multiple definition of `boost::cgi::common::basic_client<boost::cgi::common::tags::fcgi>::basic_client()'
bin/gcc-4.4.5/debug/main.o:/home/dude/include/cgi-0.7.1/boost/cgi/fcgi/client.hpp:44: first defined here
War es hilfreich?

Lösung

Dies Defektbericht Sieht relevant aus: Es scheint, dass diese "Header Only" -Bibliothek ein paar Dinge aufgerutscht ist, die nicht wirklich nur den Kopfball sind.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top