Skip to content

using OLB with multiple cpp files

OpenLB – Open Source Lattice Boltzmann Code Forums on OpenLB General Topics using OLB with multiple cpp files

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1876
    jackyko
    Member

    hi I am creating a very simple program try to include OLB headers, but some definition errors raises:

    my program includes 3 files:

    Code:
    // main.cpp
    #include “iostream”
    #include “a.h”

    using namespace std;

    int main()
    {
    PrintHello();
    }

    Code:
    // a.h
    #ifndef A_H
    #define A_H

    #include “iostream”
    #include “olb3D.h”
    #include “olb3D.hh”

    void PrintHello();

    #endif

    Code:
    // a.cpp
    #include “a.h”

    using namespace std;

    void PrintHello()
    {
    cout << “hello” <<endl;
    }

    compile the above code:

    Code:
    g++ -c main.cpp a.cpp -I ./ -I [path_to_olb.h]

    still fine at this stage, but when i try to link the library to the final binary, error comes

    Code:
    g++ main.o a.o -o main -L [path_to_prebuilt_lib] -l olb

    error comes out as for multiple defintion

    Code:
    a.o:(.bss+0x0): multiple definition of `olb::XMLreader::notFound’
    main.o:(.bss+0x0): first defined here
    a.o: In function `olb::XMLreader::XMLreader()’:
    a.cpp:(.text+0x0): multiple definition of `olb::XMLreader::XMLreader()’
    main.o:main.cpp:(.text+0x0): first defined here
    a.o: In function `olb::XMLreader::XMLreader()’:
    a.cpp:(.text+0x0): multiple definition of `olb::XMLreader::XMLreader()’
    main.o:main.cpp:(.text+0x0): first defined here
    a.o: In function `olb::XMLreader::XMLreader(TiXmlNode*)’:
    a.cpp:(.text+0x162): multiple definition of `olb::XMLreader::XMLreader(TiXmlNode*)’
    main.o:main.cpp:(.text+0x162): first defined here
    a.o: In function `olb::XMLreader::mainProcessorIni(TiXmlNode*)’:
    a.cpp:(.text+0x6a4): multiple definition of `olb::XMLreader::mainProcessorIni(TiXmlNode*)’
    main.o:main.cpp:(.text+0x6a4): first defined here
    a.o: In function `olb::XMLreader::slaveProcessorIni()’:
    a.cpp:(.text+0x896): multiple definition of `olb::XMLreader::slaveProcessorIni()’
    main.o:main.cpp:(.text+0x896): first defined here
    a.o: In function `olb::XMLreader::XMLreader(TiXmlNode*)’:
    a.cpp:(.text+0x162): multiple definition of `olb::XMLreader::XMLreader(TiXmlNode*)’
    main.o:main.cpp:(.text+0x162): first defined here
    a.o: In function `olb::XMLreader::XMLreader(std::string const&)’:
    a.cpp:(.text+0x2e8): multiple definition of `olb::XMLreader::XMLreader(std::string const&)’
    main.o:main.cpp:(.text+0x2e8): first defined here
    a.o: In function `olb::XMLreader::XMLreader(std::string const&)’:
    a.cpp:(.text+0x2e8): multiple definition of `olb::XMLreader::XMLreader(std::string const&)’
    main.o:main.cpp:(.text+0x2e8): first defined here
    a.o: In function `olb::XMLreader::~XMLreader()’:
    a.cpp:(.text+0x566): multiple definition of `olb::XMLreader::~XMLreader()’
    main.o:main.cpp:(.text+0x566): first defined here
    a.o: In function `olb::XMLreader::~XMLreader()’:
    a.cpp:(.text+0x566): multiple definition of `olb::XMLreader::~XMLreader()’
    main.o:main.cpp:(.text+0x566): first defined here
    a.o: In function `olb::XMLreader::print(int) const’:
    a.cpp:(.text+0x912): multiple definition of `olb::XMLreader::print(int) const’
    main.o:main.cpp:(.text+0x912): first defined here
    a.o: In function `olb::XMLreader::operator[](std::string) const’:
    a.cpp:(.text+0xaa6): multiple definition of `olb::XMLreader::operator[](std::string) const’
    main.o:main.cpp:(.text+0xaa6): first defined here
    a.o: In function `olb::XMLreader::begin() const’:
    a.cpp:(.text+0xb8a): multiple definition of `olb::XMLreader::begin() const’
    main.o:main.cpp:(.text+0xb8a): first defined here
    a.o: In function `olb::XMLreader::end() const’:
    a.cpp:(.text+0xbaa): multiple definition of `olb::XMLreader::end() const’
    main.o:main.cpp:(.text+0xbaa): first defined here
    a.o: In function `olb::XMLreader::getName() const’:
    a.cpp:(.text+0xbca): multiple definition of `olb::XMLreader::getName() const’
    main.o:main.cpp:(.text+0xbca): first defined here
    a.o: In function `olb::XMLreader::setWarningsOn(bool) const’:
    a.cpp:(.text+0xbf8): multiple definition of `olb::XMLreader::setWarningsOn(bool) const’
    main.o:main.cpp:(.text+0xbf8): first defined here
    a.o: In function `bool olb::XMLreader::read<bool>(bool&, bool) const’:
    a.cpp:(.text+0xc72): multiple definition of `bool olb::XMLreader::read<bool>(bool&, bool) const’
    main.o:main.cpp:(.text+0xc72): first defined here
    a.o: In function `bool olb::XMLreader::read<int>(int&, bool) const’:
    a.cpp:(.text+0xefc): multiple definition of `bool olb::XMLreader::read<int>(int&, bool) const’
    main.o:main.cpp:(.text+0xefc): first defined here
    a.o: In function `bool olb::XMLreader::read<double>(double&, bool) const’:
    a.cpp:(.text+0x109e): multiple definition of `bool olb::XMLreader::read<double>(double&, bool) const’
    main.o:main.cpp:(.text+0x109e): first defined here
    a.o: In function `bool olb::XMLreader::read<std::string>(std::string&, bool) const’:
    a.cpp:(.text+0x1244): multiple definition of `bool olb::XMLreader::read<std::string>(std::string&, bool) const’
    main.o:main.cpp:(.text+0x1244): first defined here
    a.o: In function `olb::XMLreader::getAttribute(std::string const&) const’:
    a.cpp:(.text+0x1298): multiple definition of `olb::XMLreader::getAttribute(std::string const&) const’
    main.o:main.cpp:(.text+0x1298): first defined here
    collect2: error: ld returned 1 exit status

    I would like to refactor the code in multiple files, my program work in single .cpp file but it is too long for a further development. Any help?

    #2477
    albert.mink
    Moderator

    Dear,

    I am curious about your goal of including header of OpenLB. Do you want to use OpenLB Functions in your application or extend OpenLB by own code?

    Regards,
    Albert

    #2479
    jackyko
    Member

    I am embedding the OpenLB with my own applications. The program involves an automatic vessel segmentation scheme and boundary setting part. I have finished the code in a single CPP file in reference with aorta3D example.

    The above 3 files is a simplify version of my designed framework for further development.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.