[Gmsh] link gmsh library with c++

Mikhail Artemyev artemiev.mikhail at gmail.com
Tue Jun 24 18:53:30 CEST 2014


Hello,

Did you try:
g++ -o main main.o -L/usr/lib -lgmsh

Mikhail

>       I am learning to link gmsh in a c++ code.  I tried with Takuya
> OSHIMA's code to start with.  I was able to link the header files but I
> couldn't link the gmsh library on a LINUX system from the terminal.
>
> The errors that pop up are:
>
> main.cpp:(.text+0x2e): undefined reference to `GmshInitialize(int, char**)'
>
> main.cpp:(.text+0x9c): undefined reference to
> `GmshSetOption(std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, double, int)'
>
> main.cpp:(.text+0x140): undefined reference to
> `GmshSetOption(std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, double, int)'
>
> main.cpp:(.text+0x1b9): undefined reference to
> `GModel::GModel(std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >)'
>
> main.cpp:(.text+0x218): undefined reference to
> `GModel::setFactory(std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >)'
>
> main.cpp:(.text+0x270): undefined reference to `GModel::addVertex(double,
> double, double, double)'
>
> main.cpp:(.text+0x2a3): undefined reference to `GModel::addVertex(double,
> double, double, double)'
>
> main.cpp:(.text+0x2d6): undefined reference to `GModel::addVertex(double,
> double, double, double)'
>
> main.cpp:(.text+0x309): undefined reference to `GModel::addVertex(double,
> double, double, double)'
>
> main.cpp:(.text+0x334): undefined reference to `GModel::addVertex(double,
> double, double, double)'
>
> main.cpp:(.text+0x352): undefined reference to `GModel::addLine(GVertex*,
> GVertex*)'
>
> main.cpp:(.text+0x373): undefined reference to `GModel::addLine(GVertex*,
> GVertex*)'
>
> main.cpp:(.text+0x394): undefined reference to `GModel::addLine(GVertex*,
> GVertex*)'
>
> main.cpp:(.text+0x3b5): undefined reference to `GModel::addLine(GVertex*,
> GVertex*)'
>
> main.cpp:(.text+0x4db): undefined reference to
> `GModel::addPlanarFace(std::vector<std::vector<GEdge*,
> std::allocator<GEdge*> >, std::allocator<std::vector<GEdge*,
> std::allocator<GEdge*> > > >)'
>
> main.cpp:(.text+0x543): undefined reference to
> `GModel::writeGEO(std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > const&, bool)'
>
> main.cpp:(.text+0x572): undefined reference to `GModel::mesh(int)'
>
> main.cpp:(.text+0x5d9): undefined reference to
> `GModel::writeMSH(std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > const&, double, bool, bool, bool, double, int, int)'
>
> main.cpp:(.text+0x60d): undefined reference to
> `GModel::indexMeshVertices(bool, int)'
>
> main.cpp:(.text+0x61c): undefined reference to
> `GModel::getNumMeshVertices()'
>
> main.cpp:(.text+0x642): undefined reference to
> `GModel::getMeshVertexByTag(int)'
>
> main.cpp:(.text+0x7f9): undefined reference to `GmshFinalize()'
>
> collect2: ld returned 1 exit status
>
>
> This is what I used so far:
>
> -l /usr/lib/libgmsh-2.5.1.so
>
> and
>
> g++ -o main -L/usr/lib/libgmsh.a main.o
>
> and
>
> gcc -c /usr/lib/libgmsh-2.5.1.so main.cpp
>
>
> Still I get the same errors when I compile.
>
>
> Can someone help me to link the libgmsh.a when compiling the .cpp file?