LEDA-6.3 library - c++

I am a leda-6.3 library user.
I used graphwin to manipulate and display graphs, but I found that references
to graphwin methods are undefined while compiling the code although they
are declared in the LEDA/incl/LEDA/graphics/graphwin.h
So I think it is a problem of object file.
#include <LEDA/graphics/graphwin.h>
#include <LEDA/graph/graph_alg.h>
using namespace leda;
int main()
{
GraphWin gw("LEDA Graph Editor");
node u=gw.new_node(point(100,100));
node v=gw.new_node(point(100,200));
gw.new_edge(u,v);
gw.display();
gw.get_window().read_mouse();
graph& G=gw.get_graph();
G.new_node();
gw.get_window().read_mouse();
gw.update_graph();
gw.get_window().read_mouse();
return 0;
}
compilation: g++ -I$LEDAROOT/incl -L$LEDAROOT gw.cpp -lleda -lX11 -lm -o gw
ERROR :
/tmp/ccVHyRbL.o: In function `main':
gw.cpp:(.text+0x1e): undefined reference to `leda::GraphWin::GraphWin(char const*)'
gw.cpp:(.text+0x58): undefined reference to `leda::GraphWin::new_node(leda::point const&)'
gw.cpp:(.text+0xc6): undefined reference to `leda::GraphWin::new_node(leda::point const&)'
gw.cpp:(.text+0x11c): undefined reference to `leda::GraphWin::new_edge(leda::node_struct*, leda::node_struct*)'
gw.cpp:(.text+0x128): undefined reference to `leda::GraphWin::display()'
gw.cpp:(.text+0x17e): undefined reference to `leda::GraphWin::update_graph()'
collect2: ld returned 1 exit status

Which edition of LEDA are you using?
Please consider that free edition of LEDA does not contain GraphWin.
So, it dos not contain GraphWin libraries, which results to getting such errors while compiling your program.

Related

Linking issues Boost.Python

Trying to use Boost Python, but getting linkage issues.
Code, hello.cpp:
#include <boost/python.hpp>
char const* greet() {
return "hellow, world";
}
int main() {
return 0;
}
BOOST_PYTHON_MODULE(hello_ext) {
using namespace boost::python;
def("greet", greet);
}
Compiling with:
g++ hello.cpp -L/usr/lib/x86_64-linux-gnu/ -I/usr/include/python3.5/ -lboost_python /usr/lib/x86_64-linux-gnu/libpython3.5m.so -lboost_system
Getting the following linkage errors:
tmp/ccJ8ST4B.o: In function `PyInit_hello_ext':
hello.cpp:(.text+0x94): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_Size'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyUnicodeUCS4_FromEncodedObject'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyFile_FromString'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_Type'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyInt_Type'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromString'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyUnicodeUCS4_AsWideChar'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromStringAndSize'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `Py_InitModule4_64'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromFormat'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyNumber_Divide'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyNumber_InPlaceDivide'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyInt_AsLong'
Any ideas?
Here while compiling give proper, exact and ordered path for libraries. Please use below command and try, If it doesn't work set LD_LIBRARY_PATH(set in program dir path only) to program directory path. This will link all the required library to your program directory.
g++ -I/usr/include/python3.5/ /usr/lib/x86_64-linux-gnu/libpython3.5m.so -L/usr/lib/x86_64-linux-gnu/ -lboost_python -lboost_system hello.cpp -o hello
If above line do not work
export LD_LIBRARY_PATH=/program_path:$LD_LIBRARY_PATH

Linking error with boost process (and other boost libs)

Here's my code. I'm just testing Boost::process so I'll be able to use it if/when I need to. I don't know why I'm getting the linking error that I am getting. I'm a rather novice C++ programmer. I know the concepts, but I make frequent errors in practice and am bad at debugging. I appreciate any help I can get with this.
#include<iostream>
#include<boost/process.hpp>
#include<boost/iostreams/device/file_descriptor.hpp>
namespace bp = ::boost::process;
namespace bpi = ::boost::process::initializers;
namespace bio = ::boost::iostreams;
int main(int argc, char *argv[])
{
bp::pipe p = bp::create_pipe();
bio::file_descriptor_sink sink(p.sink, bio::close_handle);
bp::execute(
bpi::run_exe("/usr/bin/ls"),
bpi::bind_stdout(sink)
);
return(0);
}
And here is my error…
/tmp/cc7cmrV8.o: In function `main':
test.cpp:(.text+0x2b): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(int, boost::iostreams::file_descriptor_flags)'
/tmp/cc7cmrV8.o: In function `boost::process::posix::initializers::bind_stdout::bind_stdout(boost::iostreams::file_descriptor_sink const&)':
test.cpp:(.text._ZN5boost7process5posix12initializers11bind_stdoutC2ERKNS_9iostreams20file_descriptor_sinkE[_ZN5boost7process5posix12initializers11bind_stdoutC5ERKNS_9iostreams20file_descriptor_sinkE]+0x2b): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/tmp/cc7cmrV8.o: In function `void boost::process::posix::initializers::bind_stdout::on_exec_setup<boost::process::posix::executor>(boost::process::posix::executor&) const':
test.cpp:(.text._ZNK5boost7process5posix12initializers11bind_stdout13on_exec_setupINS1_8executorEEEvRT_[_ZNK5boost7process5posix12initializers11bind_stdout13on_exec_setupINS1_8executorEEEvRT_]+0x18): undefined reference to `boost::iostreams::file_descriptor::handle() const'
collect2: error: ld returned 1 exit status
Platform: Linux 64-bit
Boost: 1.55 (installed via pacman)
Boost::process: 0.5
Compile command: g++ -Wall test.cpp -o spegh.elf -lboost_system
A simple search threw me at -This-.
Seeing you posted your compile command, I'm guessing you are simply missing -lboost_iostreams in your linker settings.

gcc Linker and OGDF "undefined reference to `ogdf::Initialization::Initialization()'"

I am trying to get OGDF working to see if it is suitable for my project, but I am having trouble with a sample program.
I am trying to compile this example program:
#include <ogdf/basic/Graph.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
using namespace ogdf;
int main()
{
Graph G;
randomSimpleGraph(G, 10, 20);
DfsAcyclicSubgraph DAS;
DAS.callAndReverse(G);
G.writeGML("test.gml");
return 0;
}
using this command:
$g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ -lOGDF test2.cpp
But I get the following error
/tmp/ccbpkfdt.o: In function `main':
test2.cpp:(.text+0x12): undefined reference to `ogdf::Graph::Graph()'
test2.cpp:(.text+0x2e): undefined reference to `ogdf::randomSimpleGraph(ogdf::Graph&, int, int)'
test2.cpp:(.text+0x4e): undefined reference to `ogdf::AcyclicSubgraphModule::callAndReverse(ogdf::Graph&)'
test2.cpp:(.text+0x62): undefined reference to `ogdf::Graph::writeGML(char const*) const'
test2.cpp:(.text+0x7f): undefined reference to `ogdf::Graph::~Graph()'
test2.cpp:(.text+0xa1): undefined reference to `ogdf::Graph::~Graph()'
/tmp/ccbpkfdt.o: In function `__static_initialization_and_destruction_0(int, int)':
test2.cpp:(.text+0xfb): undefined reference to `ogdf::Initialization::Initialization()'
test2.cpp:(.text+0x112): undefined reference to `ogdf::Initialization::~Initialization()'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphC2Ev[_ZN4ogdf18DfsAcyclicSubgraphC5Ev]+0x16): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::~DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphD2Ev[_ZN4ogdf18DfsAcyclicSubgraphD5Ev]+0xb): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
collect2: error: ld returned 1 exit status
I tried compiling hello world, with an include from OGDF, and I still got:
undefined reference to `ogdf::Initialization::Initialization()'
I think I am not linking properly or something?
You have to be very careful in which order you type stuff when linking with a library.
Try putting test2.cpp before -lOGDF instead, like this:
g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ test2.cpp -lOGDF
You must build your program using the -DOGDF_DLL when using OGDF as a shared library.
See here: http://www.ogdf.net/doku.php/tech:defines

Linking D library to C++ code

Recently I learned the beautiful language D, which is so more plastic and helps yourself writing stable fast programs. But its not popular... because few code written on D and so more on C and C++. Therefore after I read the book of Andrei Alexanderscu where author very superficially described question about linking of D library to C++ code, I tried learn it myself and written some code on D where defined function that returns an instance of CompleteAutomata class which implements AutomataInterface defined also in C++ code:
#ifndef AUTOMATAINTERFACE_H
#define AUTOMATAINTERFACE_H
class AutomataInterface {
public:
virtual ~AutomataInterface() {}
virtual void next() = 0;
virtual void save() = 0;
virtual void restore() = 0;
virtual void zerofile() = 0;
virtual void invert(unsigned long x, unsigned long y) = 0;
virtual int state(unsigned long x, unsigned long y) const = 0;
virtual unsigned long x() const = 0;
virtual unsigned long y() const = 0;
};
AutomataInterface *createAutomata(unsigned long x, unsigned long y);
#endif // AUTOMATAINTERFACE_H
Relevant D code:
import agregator; // this is my own lib
extern(C++) {
interface AutomataInterface {
void next();
void save();
void restore();
void zerofile();
void invert(size_t x, size_t y);
int state(size_t x, size_t y) const;
size_t x() const;
size_t y() const;
}
AutomataInterface createAutomata(ulong x, ulong y) {
return new CompleteAutomata(x, y);
}
}
export class CompleteAutomata : AutomataInterface {
// instance variables...
this(size_t x, size_t y) { /* ... */ }
extern(C++) {
override void next() {
// ...
}
// others overridden interface methods...
}
}
After code had written, I've compiling of D library by two different compilers (dmd and gdc), with following flags:
dmd -release -O -lib -odlib -ofliblife.h *.d
or
gdc -frelease -O2 -Wall -c *.d
ar cq lib/liblife.a *.o
When I trying link each of received libs to Qt project by adding path to library dir (-L option) and adding a lib directly (-l option). I got errors of in both cases.
In first dmd case I have "undefined reference to `_d_newclass'" and couple of another errors:
g++ -Wl,-O1 -Wl,-z,relro -o automata main.o mainwindow.o renderarea.o button.o playbutton.o moc_mainwindow.o moc_renderarea.o moc_button.o moc_playbutton.o -L/home/newmen/projects/d/life/lib -llife -lQtGui -lQtCore -lpthread
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1fe_5b0.o): In function `createAutomata(unsigned int, unsigned int)':
complete_automata.d:(.text._Z14createAutomatajj+0x27): undefined reference to `_d_newclass'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.data+0x0): undefined reference to `_D14TypeInfo_Class6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.data+0x50): undefined reference to `_D6Object7__ClassZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.data+0xd0): undefined reference to `_D14TypeInfo_Class6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.data+0x120): undefined reference to `_D6Object7__ClassZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x68): undefined reference to `_D6object6Object8toStringMFZAya'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x70): undefined reference to `_D6object6Object6toHashMFNbNeZm'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x78): undefined reference to `_D6object6Object5opCmpMFC6ObjectZi'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x80): undefined reference to `_D6object6Object8opEqualsMFC6ObjectZb'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0xf8): undefined reference to `_D6object6Object8toStringMFZAya'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x100): undefined reference to `_D6object6Object6toHashMFNbNeZm'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x108): undefined reference to `_D6object6Object5opCmpMFC6ObjectZi'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x110): undefined reference to `_D6object6Object8opEqualsMFC6ObjectZb'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o): In function `_D17complete_automata16CompleteAutomata6__ctorMFmmZC17complete_automata16CompleteAutomata':
complete_automata.d:(.text._D17complete_automata16CompleteAutomata6__ctorMFmmZC17complete_automata16CompleteAutomata+0x1f): undefined reference to `_d_newclass'
complete_automata.d:(.text._D17complete_automata16CompleteAutomata6__ctorMFmmZC17complete_automata16CompleteAutomata+0x46): undefined reference to `_d_newclass'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o): In function `CompleteAutomata::next()':
complete_automata.d:(.text._ZN16CompleteAutomata4nextEv+0x2f): undefined reference to `_d_newclass'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o): In function `CompleteAutomata::save()':
complete_automata.d:(.text._ZN16CompleteAutomata4saveEv+0x25): undefined reference to `_adDupT'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o): In function `CompleteAutomata::restore()':
complete_automata.d:(.text._ZN16CompleteAutomata7restoreEv+0x33): undefined reference to `_d_newclass'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o): In function `CompleteAutomata::zerofile()':
complete_automata.d:(.text._ZN16CompleteAutomata8zerofileEv+0x2f): undefined reference to `_d_newclass'
/home/newmen/projects/d/life/lib/liblife.a(object_201_8b7.o): In function `no symbol':
/usr/include/dmd/druntime/import/object.di:(.text+0x6): undefined reference to `_Dmodule_ref'
/home/newmen/projects/d/life/lib/liblife.a(object_201_8b7.o):(.data._D12TypeInfo_Axi6__initZ+0x0): undefined reference to `_D14TypeInfo_Array6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(object_201_8b7.o): In function `_D46/usr/include/dmd/druntime/import/object.di.5137__arrayZ':
/usr/include/dmd/druntime/import/object.di:(.text._D46/usr/include/dmd/druntime/import/object.di.5137__arrayZ+0x16): undefined reference to `_d_array_bounds'
/home/newmen/projects/d/life/lib/liblife.a(object_201_8b7.o): In function `_D46/usr/include/dmd/druntime/import/object.di.5138__assertFiZv':
/usr/include/dmd/druntime/import/object.di:(.text._D46/usr/include/dmd/druntime/import/object.di.5138__assertFiZv+0x16): undefined reference to `_d_assertm'
/home/newmen/projects/d/life/lib/liblife.a(object_201_8b7.o): In function `_D46/usr/include/dmd/druntime/import/object.di.51315__unittest_failFiZv':
/usr/include/dmd/druntime/import/object.di:(.text._D46/usr/include/dmd/druntime/import/object.di.51315__unittest_failFiZv+0x16): undefined reference to `_d_unittestm'
/home/newmen/projects/d/life/lib/liblife.a(object_203_875.o): In function `no symbol':
/usr/include/dmd/druntime/import/object.di:(.text+0x6): undefined reference to `_Dmodule_ref'
/home/newmen/projects/d/life/lib/liblife.a(object_203_875.o):(.data._D11TypeInfo_xi6__initZ+0x0): undefined reference to `_D14TypeInfo_Const6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(object_203_875.o):(.data._D11TypeInfo_xi6__initZ+0x10): undefined reference to `_D10TypeInfo_i6__initZ'
/home/newmen/projects/d/life/lib/liblife.a(object_203_875.o): In function `_D46/usr/include/dmd/druntime/import/object.di.5157__arrayZ':
/usr/include/dmd/druntime/import/object.di:(.text._D46/usr/include/dmd/druntime/import/object.di.5157__arrayZ+0x16): undefined reference to `_d_array_bounds'
/home/newmen/projects/d/life/lib/liblife.a(object_203_875.o): In function `_D46/usr/include/dmd/druntime/import/object.di.5158__assertFiZv':
/usr/include/dmd/druntime/import/object.di:(.text._D46/usr/include/dmd/druntime/import/object.di.5158__assertFiZv+0x16): undefined reference to `_d_assertm'
/home/newmen/projects/d/life/lib/liblife.a(object_203_875.o): In function `_D46/usr/include/dmd/druntime/import/object.di.51515__unittest_failFiZv':
/usr/include/dmd/druntime/import/object.di:(.text._D46/usr/include/dmd/druntime/import/object.di.51515__unittest_failFiZv+0x16): undefined reference to `_d_unittestm'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o): In function `no symbol':
agregator.d:(.text+0x6): undefined reference to `_Dmodule_ref'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o):(.data+0x10): undefined reference to `_D3std6random12__ModuleInfoZ'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o):(.rodata+0x20): undefined reference to `_D14TypeInfo_Class6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o): In function `_D9agregator7__arrayZ':
agregator.d:(.text._D9agregator7__arrayZ+0x16): undefined reference to `_d_array_bounds'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o): In function `_D9agregator8__assertFiZv':
agregator.d:(.text._D9agregator8__assertFiZv+0x16): undefined reference to `_d_assertm'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o): In function `_D9agregator15__unittest_failFiZv':
agregator.d:(.text._D9agregator15__unittest_failFiZv+0x16): undefined reference to `_d_unittestm'
/home/newmen/projects/d/life/lib/liblife.a(agregator_2_5fd.o):(.data+0x0): undefined reference to `_D14TypeInfo_Class6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(agregator_2_5fd.o):(.data+0x50): undefined reference to `_D6Object7__ClassZ'
/home/newmen/projects/d/life/lib/liblife.a(agregator_2_5fd.o):(.rodata+0x48): undefined reference to `_D6object6Object8toStringMFZAya'
...
In second case (when using gdc) I receives message about "multiple definition of":
g++ -Wl,-O1 -Wl,-z,relro -o cellular_life main.o mainwindow.o renderarea.o button.o playbutton.o moc_mainwindow.o moc_renderarea.o moc_button.o moc_playbutton.o -L/home/newmen/projects/d/life/lib -llife -lQtGui -lQtCore -lpthread
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `_D17complete_automata16CompleteAutomata7restoreMRZv14SliceAgregator9initValueMxFmmZi':
complete_automata.d:(.text+0x0): multiple definition of `_D17complete_automata16CompleteAutomata7restoreMRZv14SliceAgregator9initValueMxFmmZi'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._D17complete_automata16CompleteAutomata7restoreMRZv14SliceAgregator9initValueMxFmmZi+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::invert(unsigned long long, unsigned long long)':
complete_automata.d:(.text+0x40): multiple definition of `CompleteAutomata::invert(unsigned long long, unsigned long long)'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZN16CompleteAutomata6invertEyy+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::state(unsigned long long, unsigned long long) const':
complete_automata.d:(.text+0x60): multiple definition of `CompleteAutomata::state(unsigned long long, unsigned long long) const'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZNK16CompleteAutomata5stateEyy+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::x() const':
complete_automata.d:(.text+0x80): multiple definition of `CompleteAutomata::x() const'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZNK16CompleteAutomata1xEv+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::y() const':
complete_automata.d:(.text+0xa0): multiple definition of `CompleteAutomata::y() const'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZNK16CompleteAutomata1yEv+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::next()':
complete_automata.d:(.text+0x140): multiple definition of `CompleteAutomata::next()'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZN16CompleteAutomata4nextEv+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.tbss+0x10): multiple definition of `_D17complete_automata16CompleteAutomata4nextMRZv7changerC7changer7Changer'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.tbss+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::restore()':
complete_automata.d:(.text+0x1b0): multiple definition of `CompleteAutomata::restore()'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZN16CompleteAutomata7restoreEv+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.tbss+0x8): multiple definition of `_D17complete_automata16CompleteAutomata7restoreMRZv9agregatorC9agregator9Agregator'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.tbss+0x8): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.data+0x180): multiple definition of `_D_ZN16CompleteAutomata7restoreEv14SliceAgregator7__ClassZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.data+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::zerofile()':
complete_automata.d:(.text+0x220): multiple definition of `CompleteAutomata::zerofile()'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZN16CompleteAutomata8zerofileEv+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.tbss+0x0): multiple definition of `_D17complete_automata16CompleteAutomata8zerofileMRZv9agregatorC9agregator9Agregator'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.tbss+0x10): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::save()':
complete_automata.d:(.text+0x290): multiple definition of `CompleteAutomata::save()'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._ZN16CompleteAutomata4saveEv+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.data+0x80): multiple definition of `_D17complete_automata16CompleteAutomata7__ClassZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.data+0xd0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `_D17complete_automata16CompleteAutomata6__ctorMFmmZC17complete_automata16CompleteAutomata':
complete_automata.d:(.text+0x9b0): multiple definition of `_D17complete_automata16CompleteAutomata6__ctorMFmmZC17complete_automata16CompleteAutomata'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):complete_automata.d:(.text._D17complete_automata16CompleteAutomata6__ctorMFmmZC17complete_automata16CompleteAutomata+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.rodata+0x420): multiple definition of `_D17complete_automata16CompleteAutomata6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0xf0): first defined here
/usr/bin/ld: Warning: size of symbol `_D17complete_automata16CompleteAutomata6__vtblZ' changed from 104 in /home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o) to 112 in /home/newmen/projects/d/life/lib/liblife.a(complete_automata.o)
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.rodata+0x4a0): multiple definition of `_D17complete_automata16CompleteAutomata6__initZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x90): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.rodata+0x4e0): multiple definition of `_D_ZN16CompleteAutomata7restoreEv14SliceAgregator6__vtblZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x60): first defined here
/usr/bin/ld: Warning: size of symbol `_D_ZN16CompleteAutomata7restoreEv14SliceAgregator6__vtblZ' changed from 48 in /home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o) to 56 in /home/newmen/projects/d/life/lib/liblife.a(complete_automata.o)
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o):(.rodata+0x520): multiple definition of `_D_ZN16CompleteAutomata7restoreEv14SliceAgregator6__initZ'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1ff_675.o):(.rodata+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(agregator.o): In function `_D3std7complex14__T7ComplexTeZ7Complex8toStringMxFMDFAxaZvAyaZAya12__lambda1223MFNbNfAxaZv':
agregator.d:(.text+0xaf): undefined reference to `_D11TypeInfo_Aa6__initZ'
agregator.d:(.text+0xb7): undefined reference to `_d_arrayappendT'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o): In function `_D3std4conv16__T6toImplTiTxkZ6toImplFNaNfxkZi15__dgliteral1389MFNaNfZC6object9Throwable':
agregator.d:(.text+0xc5): undefined reference to `_D3std4conv21ConvOverflowException7__ClassZ'
agregator.d:(.text+0xca): undefined reference to `_d_newclass'
agregator.d:(.text+0xed): undefined reference to `_D3std4conv21ConvOverflowException6__ctorMFAyaAyamZC3std4conv21ConvOverflowException'
/home/newmen/projects/d/life/lib/liblife.a(agregator.o): In function `_D3std6format17__T9getNthIntTxeZ9getNthIntFNaNfkxeZi.part.6':
agregator.d:(.text+0x105): undefined reference to `_D3std6format15FormatException7__ClassZ'
agregator.d:(.text+0x10a): undefined reference to `_d_newclass'
...
After two days of attempts to do so...
Recently I've try add Phobos (D standard library) to linking process. For dmd -lphobos2 flag and for gdc -lgphobos2 flag correspond. But it not help me...
When using dmd linker output:
g++ -Wl,-O1 -Wl,-z,relro -o cellular_life main.o mainwindow.o renderarea.o button.o playbutton.o moc_mainwindow.o moc_renderarea.o moc_button.o moc_playbutton.o -L/home/newmen/projects/d/life/lib -llife -lQtGui -lQtCore -lpthread -lphobos2
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_easy_duphandle#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_easy_strerror#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_slist_free_all#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_global_init#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_easy_perform#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_easy_init#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_easy_pause#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `_Dmain'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_easy_setopt#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_slist_append#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_global_cleanup#CURL_GNUTLS_3'
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libphobos2.so: undefined reference to `curl_easy_cleanup#CURL_GNUTLS_3'
collect2: error: ld returned 1 exit status
make: *** [cellular_life] Error 1
and I've try substitute of libcurl-gnutls: ln -s /usr/lib64/libcurl.so.4 /usr/lib64/libcurl-gnutls.so.4. Then result of linking the same but without message about libcurl-gnutls.
When using gdc linker output again talk about "multiple definition to":
/home/newmen/gcc/bin/g++ -Wl,-O1 -Wl,-z,relro -o cellular_life main.o mainwindow.o renderarea.o button.o playbutton.o moc_mainwindow.o moc_renderarea.o moc_button.o moc_playbutton.o -L/home/newmen/gcc/lib64 -L/home/newmen/projects/d/life/lib -llife -lQtGui -lQtCore -lpthread -lgphobos2
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `_D17complete_automata16CompleteAutomata7restoreMRZv14SliceAgregator9initValueMxFmmZi':
complete_automata.d:(.text+0x0): multiple definition of `_D17complete_automata16CompleteAutomata7restoreMRZv14SliceAgregator9initValueMxFmmZi'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1e3_675.o):complete_automata.d:(.text._D17complete_automata16CompleteAutomata7restoreMRZv14SliceAgregator9initValueMxFmmZi+0x0): first defined here
/home/newmen/projects/d/life/lib/liblife.a(complete_automata.o): In function `CompleteAutomata::invert(unsigned long long, unsigned long long)':
complete_automata.d:(.text+0x40): multiple definition of `CompleteAutomata::invert(unsigned long long, unsigned long long)'
/home/newmen/projects/d/life/lib/liblife.a(complete_automata_1e3_675.o):complete_automata.d:(.text._ZN16CompleteAutomata6invertEyy+0x0): first defined here
...
/home/newmen/gcc/lib64/libgphobos2.a(dmain2.o): In function `main':
/home/newmen/projects/distrib/gcc-4.8.1/x86_64-unknown-linux-gnu/libphobos/libdruntime/../../.././libphobos/libdruntime/rt/dmain2.d:394: multiple definition of `main'
main.o:/home/newmen/projects/d/life/qt_viewer/main.cpp:5: first defined here
/usr/bin/ld: /home/newmen/gcc/lib64/libgphobos2.a(time.o): undefined reference to symbol 'clock_getres##GLIBC_2.2.5'
/usr/bin/ld: note: 'clock_getres##GLIBC_2.2.5' is defined in DSO /lib64/librt.so.1 so try adding it to the linker command line
/lib64/librt.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [cellular_life] Error 1
with message about librt.so.1 at end. I inspect /usr/lib64 and seen there it library file.
Dear magic, please tell me how to connect the D library to C++ code.
It is generally easier to let the D compiler do the linking:
g++ -c yourfile.cpp
dmd yourfile.o d_file.d
You might have to add curl to it as well, same as you did before. To pass a linker argument through dmd (or gdmd if you're using gdc, should work the same way), pass -Larg
dmd yourfile.o d_file.d -L-lstdc++ -L-lcurl -L-lQtGui # and so on
It is generally easier to put main() in D too (it can just immediately call out to a C++ defined function too) because otherwise you'll probably have to initialize the D runtime before using it from C++.
But to finish the process you've started... first thing, looks like your liblife.a has the same file added twice. I'd try deleting that file and recreating it, or just skipping that step and passing the .o files to the linker directly without first packing them into a .a. That'll simplify things a bit.
My other question is: why is it trying to pull the D main? Is there a main() in your .d code somewhere? If so, that's ok, but you'll have to remove the one from your C++ code. (Perhaps rename it into cppmain and then call it from the D main:
D code:
extern(C++) int cppmain(int argc, char** argv);
int main() {
import core.runtime;
return cppmain(Runtime.cArgs.argc, Runtime.cArgs.argv);
}
And that will forward to your C++ main. If you want to remove the D main (assuming it is there, if not let me know and I'll try to think what else could cause that linker error), before tou use D code in C++, you'll want to initialize D. So:
D code:
extern(C++) void initD() {
import core.runtime;
Runtime.initialize();
}
C++ code:
extern "C++" void initD();
int main() {
initD();
// the rest of your stuff
}
If you don't do that, calling D functions is liable to cause a segfault.
But to sum up, I'm pretty sure you have a duplicate .o file added to your archive, and main defined in both D and C++. Delete the duplicate in the archive and kill one of the duplicate mains and you should have some success.

Compiling program gives "undefined reference"

I'm lost here. I've been compiling my program successfully on LLVM on my Mac, but when I went to a Linux server and attempted to use g++ to compile, I got a boat load of linker errors.
Here's an excerpt:
/tmp/ccGbgd6T.o: In function `Scene::setBackgroundImage(String)':
Project.cpp:(.text+0x166): undefined reference to `Graph_lib::Image::Image(Point, String, Graph_lib::Suffix::Encoding)'
/tmp/ccGbgd6T.o: In function `Graph_lib::Window::~Window()':
Project.cpp:(.text._ZN9Graph_lib6WindowD2Ev[_ZN9Graph_lib6WindowD5Ev]+0xc): undefined reference to `vtable for Graph_lib::Window'
/tmp/ccGbgd6T.o: In function `Graph_lib::Shape::~Shape()':
Project.cpp:(.text._ZN9Graph_lib5ShapeD2Ev[_ZN9Graph_lib5ShapeD5Ev]+0xb): undefined reference to `vtable for Graph_lib::Shape'
/tmp/ccGbgd6T.o: In function `Graph_lib::Text::Text(Point, String const&)':
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0xe): undefined reference to `Graph_lib::Shape::Shape()'
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0x17): undefined reference to `vtable for Graph_lib::Text'
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0x67): undefined reference to `Graph_lib::Shape::add(Point)'
/tmp/ccGbgd6T.o: In function `Graph_lib::Button::Button(Point, int, int, String const&, void (*)(void*, void*))':
Project.cpp:(.text._ZN9Graph_lib6ButtonC2E5PointiiRK6StringPFvPvS5_E[_ZN9Graph_lib6ButtonC5E5PointiiRK6StringPFvPvS5_E]+0x40): undefined reference to `vtable for Graph_lib::Button'
This scared me, but then I noticed that all the errors are coming from the same class: Graph_lib. Here's an extremely cut out version of what Graph.h looks like: (note, this is not my class)
#ifndef GRAPH_GUARD
#define GRAPH_GUARD 1
#include <...system stuff...>
namespace Graph_lib {
// lots of other classes in here
// this is just one
struct Image : Shape {
Image(Point xy, string file_name, Suffix::Encoding e = Suffix::none);
//rest of class
}
}
What could be going wrong here?
Edit: this is the command I'm using to compile:
g++-4.6 -std=c++0x *.cpp -lfltk -lfltk_images
It appears as though you have forgotten to link your project with Graph.cpp, or whatever file(s) hold the implementations of the Graph_lib class methods.
Looks like your Graph library is missing.
When linking using g++, use -l <Graph lib>