Error for the header file of goblin library in c++ - c++

I am trying to use Goblin library which is used for special network algorithms. This library provides some header files and objects in C/C++. So, you can easily add a header file to your program and use some special classes and functions.
Unfortunately, when I add the header file, I get error. In the following you can see the simple code and error.
Source:
#include<goblin.h>
int main()
{
return 0;
}
Error:
$ g++ -o test.o test.cpp
/tmp/ccB0Rb25.o: In function `goblinRootObject::~goblinRootObject()':
test.cpp:(.text._ZN16goblinRootObjectD1Ev[goblinRootObject::~goblinRootObject()]+0x10): undefined reference to `goblinNObjects'
test.cpp:(.text._ZN16goblinRootObjectD1Ev[goblinRootObject::~goblinRootObject()]+0x18): undefined reference to `goblinNObjects'
test.cpp:(.text._ZN16goblinRootObjectD1Ev[goblinRootObject::~goblinRootObject()]+0x2c): undefined reference to `goblinRootObject::operator delete(void*)'
/tmp/ccB0Rb25.o: In function `goblinRootObject::~goblinRootObject()':
test.cpp:(.text._ZN16goblinRootObjectD0Ev[goblinRootObject::~goblinRootObject()]+0x10): undefined reference to `goblinNObjects'
test.cpp:(.text._ZN16goblinRootObjectD0Ev[goblinRootObject::~goblinRootObject()]+0x18): undefined reference to `goblinNObjects'
test.cpp:(.text._ZN16goblinRootObjectD0Ev[goblinRootObject::~goblinRootObject()]+0x2c): undefined reference to `goblinRootObject::operator delete(void*)'
collect2: ld returned 1 exit status

try:
g++ -lgoblin -L/pathToLibgoblin/ -o test.o test.cpp

Related

How to call function in .so file using dlopen() and dlsym()?

With the help of Shared libraries with GCC on Linux I tried to make libadd1.so and succeeded. The code runs perfectly.
But when I tried the same thing using dlopen() and dlsym() I got errors as shown below.
$ g++ -L/home/shreya/Desktop/soFiles -Wall -o test main.c -ladd1
main.c: In function ‘int main()’:
main.c:14:14: warning: variable ‘ptrVar’ set but not used [-Wunused-but-set-variable]
pt2function ptrVar;
^
/tmp/ccpdIje6.o: In function `main':
main.c:(.text+0x19): undefined reference to `dlopen'
main.c:(.text+0x29): undefined reference to `dlerror'
main.c:(.text+0x54): undefined reference to `dlerror'
main.c:(.text+0x68): undefined reference to `dlsym'
main.c:(.text+0x71): undefined reference to `dlerror'
main.c:(.text+0x1ca): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
$
Can any one tell me what's wrong?
See the manpage. For Linux, you have to link with -ldl for using the dynamic linking functions. This is a bit of a hassle because e.g. on FreeBSD, they are part of the standard library.
BTW, linking the library that you want to open dynamically (in your case -ladd1) doesn't make sense.

undefined reference to `sqlite3_open'

I am trying to follow some sqlite C++ tutorial to be able to access a database from within C++ code on Linux. sqlite3 is installed and working, but when I try to compile the example code given on the link (Create a Table) I get the following error:
g++ build/test.o -o bin/test -pthread -L lib
build/test.o: In function `main':
/home/alexander/Projects/Test/src/test.cpp:22: undefined reference to `sqlite3_open'
/home/alexander/Projects/Test/src/test.cpp:24: undefined reference to `sqlite3_errmsg'
/home/alexander/Projects/Test/src/test.cpp:39: undefined reference to `sqlite3_exec'
/home/alexander/Projects/Test/src/test.cpp:42: undefined reference to `sqlite3_free'
/home/alexander/Projects/Test/src/test.cpp:46: undefined reference to `sqlite3_close'
collect2: error: ld returned 1 exit status
Do I need to install something else? Or do I need to set some paths?
I have no practice in compiling straight from the shell.
In CodeBlocks it is necessary to point the paths of the “sqlite3.h” header and the “libsqlite3.so” dll.
If the dll is not specified in Linker Settings, exactly the mentioned problem occurs.

Undefine reference of <function name>

When I've try to compile program (test for my lib) I've got undefined reference of for every called method. I've read answers on "gcc undefined reference to", but it has not help.
PS I using: Debian 7.2.0 and C++11 standart.
#include <RFw/String.hpp>
#include <stdio.h>
using namespace RFw;
int main() {
Array<char> _arr_ (5);
_arr_[0] = 'b';
_arr_[1] = 'c';
printf("%c%c\n", _arr_[0], _arr_[2]);
printf(RFw::getVersion());
return 0;
}
Makefile target:
test:
c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}
Console output:
test.cpp:13:9: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
printf(RFw::getVersion());
^~~~~~~~~~~~~~~~~
1 warning generated.
/tmp/test-lxdZF4.o: In function `main':
test.cpp:(.text+0x20): undefined reference to `RFw::Array<char>::Array(int)'
test.cpp:(.text+0x33): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x54): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x75): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x99): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0xff): undefined reference to `RFw::Array<char>::~Array()'
test.cpp:(.text+0x11a): undefined reference to `RFw::Array<char>::~Array()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::operator[](int) const'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::Array(int)'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::getLength() const'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Exception::onThrow()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::resize(int)'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::addElementOnEnd(char)'
./bin/libregemfw0.1-core.so: undefined reference to `vtable for RFw::Object'
./bin/libregemfw0.1-core.so: undefined reference to `typeinfo for RFw::Object'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Object::~Object()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::~Array()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Ошибка 1
The problem is that
c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}
will first process the library and then your .cpp file. When processing a library, referenced symbols are resolved ("linked") and all unresolved symbols in the library that aren't needed are thrown away. That means that as soon as your .cpp file is being processed, these symbols are already rejected. You have the library twice in your command line, but the second one is being ignored since the library was already processed.
You should always put the libraries (once) at the end of the compiler command line:
c++ test.cpp -I./include-core/ -o bin/test test.cpp -L./bin -l${core_NAME_ROOT}

How does gcc link static library?

I have a simple program use static library for control pci device. I have got some examples. But i want to make myself some examples but i can't link static libraries.
I have 3 file: led.cpp main.cpp main.h
gcc -c led.cpp -I../utils -I../driver -o led.o
gcc -c main.cpp -I../utils -I../driver -o main.o
it' s ok. Succesfuly creating main.o and led.o object files.
But when linking state, its broken. 24dsi20c500k_utils.a and 24dsi20c500k_dsl.a static libraries.
gcc led.o main.o ../utils/24dsi20c500k_utils.a ../docsrc/24dsi20c500k_dsl.a -o led
Output is shown:
led.o: In function `led_tests(int)':
led.cpp:(.text+0x18): undefined reference to `gsc_label(char const*)'
led.cpp:(.text+0x31): undefined reference to `dsi20c500k_initialize(int, int)'
led.cpp:(.text+0x39): undefined reference to `gsc_label_level_inc()'
led.cpp:(.text+0x5b): undefined reference to `dsi20c500k_led(int, int, int, int*)'
led.cpp:(.text+0x81): undefined reference to `dsi20c500k_led(int, int, int, int*)'
led.cpp:(.text+0xa2): undefined reference to `gsc_label_level_dec()'
led.cpp:(.text+0xb1): undefined reference to `dsi20c500k_initialize(int, int)'
main.o: In function `_perform_tests(int)':
main.cpp:(.text+0x3a1): undefined reference to `gsc_label(char const*)'
main.cpp:(.text+0x3c6): undefined reference to `gsc_id_driver(int, char const*)'
main.o: In function `main':
main.cpp:(.text+0x42c): undefined reference to `gsc_label_init(int)'
main.cpp:(.text+0x49a): undefined reference to `gsc_id_host()'
main.cpp:(.text+0x4a4): undefined reference to `gsc_count_boards(char const*)'
main.cpp:(.text+0x4b6): undefined reference to `gsc_select_1_board(int, int*)'
main.cpp:(.text+0x4d7): undefined reference to `gsc_label(char const*)'
main.cpp:(.text+0x500): undefined reference to `gsc_dev_open(unsigned int, char const*)'
main.cpp:(.text+0x54f): undefined reference to `gsc_dev_close(unsigned int, int)'
collect2: ld returned 1 exit status
make: *** [led] Error 1
if i rename cpp files to c files compilation succesfull. What is the problem?
gcc -c main.cpp will compile your code as C++ code.
What likely happens then, is that your main.cpp includes other header files, that are not meant to be compiled as C++. This means that when including these header files in a C++ program , gcc will assume all the stuff the header files declares are C++.
And if they're not, you get linker errors if you try to link to C code that the compiler assumed was C++.
You can remedy this by stating that those header files are C. e.g. in your main.cpp you'd do
extern "C" {
#include "some_c_lib.h"
}
You probably didn't use extern "C".
if i rename cpp files to c files compilation succesfull. What is the
problem?

When I run cxxtest I get an undefined reference error

I'm not sure to understand the undefined reference I am getting.
./cxxtest/cxxtestgen.py -o tests.cpp --error-printer DrawTestSuite.h
g++ -I./cxxtest/ -c tests.cpp
g++ -o tests tests.o Color.o
tests.o: In function `DrawTestSuite::testLinewidthOne()':
tests.cpp:(.text._ZN13DrawTestSuite16t… undefined reference to `Linewidth::Linewidth(double)'
tests.cpp:(.text._ZN13DrawTestSuite16t… undefined reference to `Linewidth::draw(std::basic_ostream<char… std::char_traits<char> >&)'
collect2: ld returned 1 exit status
make: *** [tests] Error 1// DrawTestSuite.h
DrawTestSuite.h contains the unit-test and The test function calls on Linewidth.h to execute the constructer and member function draw.
I have #include "Linewidth.h"in DrawTestSuite.h.
"Undefined reference" is a linker error when a function has been properly declared and used, but the definition has not been included when linking.
You need to link with Linewidth.o, which is the object file from compiling Linewdith.cpp and the likely location where those functions are implemented.
I'm not familiar with cxxtest to know how it expects you to specify that dependency, but I suspect it only requires a simple declaration.