Last Updated
Viewed 10 Times
              

The problem is compounded by the fact that I am far from programming.

I need to use the TPC-E test. I downloaded the source codes from their website.

There is a miserable and almost meaningless ReadMe. Here are its contents:

To use the Makefile you must first set the following environment variables 
to match your system and compiler requirements:

CXX: path and name of compiler
    ex: export CXX=/opt/SUNWspro/bin/CC  (C++ compiler on Solaris)
CCFLAGS: compiler options
    ex: export CCFLAGS="-g -O"  
        -g enable debug
        -O optimize code
LDFLAGS: linker/loader options
    ex: export LDFLAGS="-g"
LIBS: extra libraries to link in
    ex: export LIBS="-lpthread"

According to the instructions there, I created the necessary environment variables (I just removed the -g switch from the CCFLAGS variable). After that, I ran the make utility and got more than five thousand lines of errors. Apparently he lacks some libraries. On this my knowledge ends.

Here are some error messages received:

...

/usr/bin/ld: DateTime.o: in function `TPCE::CDateTime::Validate(int, int, int, int, int, int, int)': DateTime.cpp:(.text+0xee): undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)'
/usr/bin/ld: DateTime.cpp:(.text+0xfd): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: DateTime.cpp:(.text+0x107): undefined reference to `__cxa_allocate_exception'
/usr/bin/ld: DateTime.cpp:(.text+0x117): undefined reference to `std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const'
/usr/bin/ld: DateTime.cpp:(.text+0x122): undefined reference to `std::out_of_range::out_of_range(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: DateTime.cpp:(.text+0x135): undefined reference to `operator delete(void*)'

...

/usr/bin/ld: error.cpp:(.text._ZN4TPCE10CSystemErrD0Ev[_ZN4TPCE10CSystemErrD5Ev]+0x24): undefined reference to `std::exception::~exception()'
/usr/bin/ld: error.cpp:(.text._ZN4TPCE10CSystemErrD0Ev[_ZN4TPCE10CSystemErrD5Ev]+0x31): undefined reference to `operator delete(void*, unsigned long)'
/usr/bin/ld: error.o: in function `TPCE::CSystemErr::~CSystemErr()':error.cpp:(.text._ZN4TPCE10CSystemErrD2Ev[_ZN4TPCE10CSystemErrD5Ev]+0x1c): undefined reference to `operator delete(void*)'

...

/usr/bin/ld: locking.cpp:(.text+0x1fb): undefined reference to `operator delete(void*)'
/usr/bin/ld: locking.cpp:(.text+0x202): undefined reference to `std::runtime_error::~runtime_error()'
/usr/bin/ld: locking.cpp:(.text+0x209): undefined reference to `typeinfo for std::runtime_error'
/usr/bin/ld: locking.cpp:(.text+0x211): undefined reference to `__cxa_throw'
/usr/bin/ld: locking.o: in function `TPCE::CMutex::lock()':locking.cpp:(.text+0x246): undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)'

...

A search on the internet made me think of installing the libboost-all-dev package, but that didn't help. In the end, I gave up - I’m completely incomprehensible to the terminology and I don’t have time to study C ++ programming.

Operating System - Debian 10

Questions: which libraries need to be installed and is there anyone who used these tests, how to adapt them to PostgreSQL?

Full error log (892 230 bytes)

I have a "small" graphics library I'm building, and I'm running into this error when attempting to build a test binary that links against it:

al_test.o: In function `test_wave()':
al_test.cpp:(.text+0x1a7): undefined reference to `min::wave::wave(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
...

(and other, similar errors, but we'll focus on this one). The library is built in a makefile with the following rules:

all: libmgl.a libmgl.so

libmgl.so: $(OBJECTS)
    $(LD) $* $(LDFLAGS) -shared -o $@

libmgl.a: $(OBJECTS)
    $(AR) $(ARFLAGS) libmgl.a $^

%.o: %.cpp
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o $@ $<

CXXFLAGS contains a few things, but most importantly -std=c++14 -O3 -Wall -Werror and all of the objects compile just fine and the static and dynamic libraries are output without error or warning.

Now I have a file source/test/al_test.cpp meant to test only the audio portions of the library that looks something like this:

#include <iostream>
#include "twave.h"
int main()
{
    try
    {
        bool out = true;
        out = out && test_wave();
        // out = out && test_ogg();
        // out = out && test_sound_buffer();
        if (out)
        {
            std::cout << "Sound tests passed!" << std::endl;
            return 0;
        }
    }
    catch (std::exception &ex)
    {
        std::cout << ex.what() << std::endl;
    }

    std::cout << "Sound tests failed!" << std::endl;
    return -1;
}

and the function test_wave is defined in twave.h like this:

#include <stdexcept>
#include "min/wave.h"
bool test_wave()
{
    bool out = true;

    // Load invention wav file
    {
        const min::wave sound = min::wave("data/sound/invention_no_1.wav");

        // File should not be mono
        out = out && !sound.is_mono();
        if (!out)
        {
            throw std::runtime_error("Failed wave file not is_mono");
        }

        // Other checks that aren't important...
    }

    return out;
}

So here's my problem: min::wave::wave() definitely exists and definitely ought to be in the library. Here's a stripped-down min/wave.h:

#ifndef __WAVE__
#define __WAVE__
#include <string>
namespace min {
class wave
{
  private:
    void load(const std::string);
  public:
    wave(const std::string&);
};
}
#endif

and min/wave.cpp

#include "wave.h"

min::wave::wave(const std::string &file)
{
    load(file);
}

// Definition of `load` omitted; I don't think it's important,
// but know that it is here

So the file exists, the function declaration and definition both exist, and I can see in my make output that wave.o is being built and linked/archived into libmgl.a/libmgl.so. Yet the compiler claims it doesn't exist. It doesn't seem to be a link order problem; here's my process for building the tests:

g++ -c -Imin/ al_test.cpp -o al_test.o
g++ al_test.o -L. -lmgl -lX11 -lGL -lfreetype -lopenal -lvorbisfile -o bin/al_test

mgl is obviously the name of my library, and those are the other things on which it depends. I also tried replacing -L. with -L/absolute/path/to/project/directory/, to no avail.

Why does g++ think my function is undefined?

nm commands

By popular demand, here are a few nm commands and their outputs:

the static library:

nm -C libmgl.a | grep wave
wavefront.o
wave.o:
0000000000000090 T min::wave::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
0000000000000000 W void min::wave::load<min::mem_file>(min::mem_file const&)
0000000000000000 W void min::wave::load<std::vector<unsigned char, std::allocator<unsigned char> > >(std::vector<unsigned char, std::allocator<unsigned char> > const&)
0000000000000000 T min::wave::clear()
0000000000000880 T min::wave::wave(min::mem_file const&)
0000000000000720 T min::wave::wave(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
0000000000000880 T min::wave::wave(min::mem_file const&)
0000000000000720 T min::wave::wave(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
0000000000000080 T min::wave::get_sample_rate() const
0000000000000060 T min::wave::get_data_samples() const
0000000000000050 T min::wave::get_bits_per_sample() const
0000000000000040 T min::wave::data() const
0000000000000020 T min::wave::is_mono() const
0000000000000030 T min::wave::is_stereo() const
0000000000000550 T min::sound_buffer::add_wave_pcm(min::wave const&)
                 U min::wave::get_sample_rate() const
                 U min::wave::get_bits_per_sample() const
                 U min::wave::data() const
                 U min::wave::is_stereo() const

...the dynamic library:

nm -C libmgl.so
0000000000201020 B __bss_start
0000000000201020 b completed.7631
                 w __cxa_finalize
0000000000000460 t deregister_tm_clones
00000000000004f0 t __do_global_dtors_aux
0000000000200e88 t __do_global_dtors_aux_fini_array_entry
0000000000201018 d __dso_handle
0000000000200e90 d _DYNAMIC
0000000000201020 D _edata
0000000000201028 B _end
000000000000053c T _fini
0000000000000530 t frame_dummy
0000000000200e80 t __frame_dummy_init_array_entry
0000000000000548 r __FRAME_END__
0000000000201000 d _GLOBAL_OFFSET_TABLE_
                 w __gmon_start__
0000000000000420 T _init
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
00000000000004a0 t register_tm_clones
0000000000201020 d __TMC_END__

...and the test file:

nm -C al_test.o
                 U __cxa_allocate_exception
                 U __cxa_atexit
                 U __cxa_begin_catch
                 U __cxa_end_catch
                 U __cxa_free_exception
                 U __cxa_throw
                 U __dso_handle
00000000000000e0 t _GLOBAL__sub_I__Z9test_wavev
                 U __gxx_personality_v0
0000000000000000 r .LC1
0000000000000000 T main
                 U __stack_chk_fail
                 U _Unwind_Resume
0000000000000000 T test_wave()
                 U operator delete(void*)
                 U min::wave::wave(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
                 U min::wave::is_mono() const
                 U std::runtime_error::runtime_error(char const*)
                 U std::runtime_error::~runtime_error()
                 U std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)
                 U std::ios_base::Init::Init()
                 U std::ios_base::Init::~Init()
                 U std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)
                 U std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
                 U std::cout
                 U std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
0000000000000000 b std::__ioinit
                 U typeinfo for std::runtime_error
                 U typeinfo for std::exception

Suppose you have have a makefile containing two targets as in the following:

# targetA
X86CPPTARGET += targetA
targetA,SRCS = FILEA.cpp  FILEB.cpp commonFile.cpp
targetA.so,DEPSOL = libUsedByCommon1.cpp
targetA,CPPFLAGS += -Ifakeinclude -std=c++11

# tartargetBgetA
X86CPPTARGET += targetB
targetB,SRCS = FILEC.cpp  FILED.cpp commonFile.cpp
targetA.so,DEPSOL = libUsedByCommon2.cpp
targetB,CPPFLAGS += -std=c++11

targetA and targetB share a file, namely, commonFile.cpp which contains a number of #included headers. commonFile.o is created only once by GNU make and reused during the compilation of targetB.

The CPPFLAGS present in targetA makes the compiler use an include that contains more symbols that the one that is in the default include directory. libUsedByCommon2 does not export all the additional symbols that are contained in the header in the fakeinclude directory and at link time, this results in undefined reference.

The workaround I am usingat the moment is to create a symbolic link to commonFile.cpp and use that in my makefile in only one of the target.

# targetA
X86CPPTARGET += targetA
targetA,SRCS = FILEA.cpp  FILEB.cpp commonFile.cpp
targetA.so,DEPSOL = libUsedByCommon1.cpp
targetA,CPPFLAGS += -Ifakeinclude -std=c++11

# tartargetBgetA
X86CPPTARGET += targetB
targetB,SRCS = FILEC.cpp  FILED.cpp **commonFile_symbolic_link.cpp**
targetA.so,DEPSOL = libUsedByCommon2.cpp
targetB,CPPFLAGS += -std=c++11

Is there a cleaner solution to this problem? Is there a way to force GNU make to recompile commonFile.cpp when a different include path is being used?

I'm currently struggling with linking a C++ project that requires linking with GLFW3, i.e., ld is called with -lglfw3. The thing is that this worked before, and right now I have no clue, why it is not anymore.

sudo  pkg-config --libs glfw3 
-L/usr/local/lib -lglfw3  

The library exists also at that specific location printed by the statement above. However, ld says:

Linking CXX executable modeling_2014_framework
/usr/bin/ld: error: cannot find -lglfw3
CMakeFiles/modeling_2014_framework.dir/main.cpp.o:main.cpp:function init(): error: undefined reference to 'glfwInit'
...
collect2: error: ld returned 1 exit status
make[2]: *** [modeling_2014_framework] Error 1
make[1]: *** [CMakeFiles/modeling_2014_framework.dir/all] Error 2
make: *** [all] Error 2

I'm using cmake to create the makefile. This is how the CMakeLists looks like:

cmake_minimum_required (VERSION 2.8)

set (project_name modeling_2014_framework)

# create project
project (${project_name})

# sources
set(SOURCES main.cpp)

# add headers to the project
file(GLOB MY_HEADERS "src/*.h")
list(APPEND HEADERS ${MY_HEADERS})

# add sources to the project
file(GLOB MY_SOURCES "src/*.cpp")
list(APPEND SOURCES ${MY_SOURCES})

# i also tried to manually set them here, which however also does not help
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/lib)

# OpenGL
find_package(OpenGL REQUIRED)   
if (NOT OPENGL_FOUND)
    message (FATAL_ERROR "OpenGL not found!")
    return()
endif ()

# glew
if (UNIX)
    set(GLEW_LIBRARY libGLEW.so)                
else()
    set (GLEW_INCLUDE_DIR "" CACHE PATH "glew include directory")
    set (GLEW_LIBRARY_DIR "" CACHE PATH "glew build directory")
    if (GLEW_INCLUDE_DIR STREQUAL  "" AND GLEW_LIBRARY_DIR STREQUAL  "")
        return()
    else()
        find_library(GLEW_LIBRARY NAMES GLEW glew32 glew glew32s PATHS ${GLEW_LIBRARY_DIR})
    endif() 
endif(UNIX)

# glfw
set (GLFW_STATIC FALSE CACHE BOOL "link against static or dynamic glfw3 library")
if (WIN32)
    set (GLFW_INCLUDE_DIR "" CACHE PATH "GLFW include directory")
    set (GLFW_LIBRARY_DIR "" CACHE PATH "GLFW build directory")
    if (GLFW_INCLUDE_DIR STREQUAL "" AND GLFW_LIBRARY_DIR STREQUAL  "")
        return()
    else()
        if (GLFW_STATIC)
            find_library(GLFW_LIBS NAMES glfw3 PATHS ${GLFW_LIBRARY_DIR})
        else(GLFW_STATIC)
            find_library(GLFW_LIBS NAMES glfw3dll PATHS ${GLFW_LIBRARY_DIR})
        endif(GLFW_STATIC)  
    endif() 
else()
    find_package(PkgConfig REQUIRED)
    pkg_search_module(GLFW REQUIRED glfw3)
    if (GLFW_STATIC)
        set (GLFW_LIBS ${GLFW_STATIC_LIBRARIES})
    else(GLFW_STATIC)
        set (GLFW_LIBS ${GLFW_LIBRARIES})
    endif(GLFW_STATIC)
    list(APPEND GLFW_LIBS libXxf86vm.so)    
    list(APPEND GLFW_LIBS libGLU.so)        
    list(APPEND GLFW_LIBS libX11.so)
    list(APPEND GLFW_LIBS libXrandr.so)
    list(APPEND GLFW_LIBS libpthread.so)
    list(APPEND GLFW_LIBS libXi.so)
endif()

include_directories(${GLEW_INCLUDE_DIR}
                ${GLFW_INCLUDE_DIR}
                    ${OPENGL_INCLUDE_DIR}
                )

# executable
add_executable(${project_name} ${SOURCES} ${HEADERS})

target_link_libraries(${project_name} 
                      ${OPENGL_LIBRARIES}
                  ${GLEW_LIBRARY}
                  ${EXTRA_LIBS}
                  ${GLFW_LIBS}
                      )

If I run the ld command manually and add -L/usr/local/lib then the linker runs fine. So my most important question would be, how to make sure that cmake adds this path to the makefile so that ld runs fine.

Thanks in advance =)

Edit1: as per request, the stdout with verbose logging:

myname@fxt ~/courses/Modellierung/proj/exercise1 $ make VERBOSE=1
/usr/bin/cmake -H/home/myname/courses/Modellierung/proj/exercise1 -B/home/myname/courses/Modellierung/proj/exercise1 --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/myname/courses/Modellierung/proj/exercise1/CMakeFiles /home/myname/courses/Modellierung/proj/exercise1/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/myname/courses/Modellierung/proj/exercise1'
make -f CMakeFiles/modeling_2014_framework.dir/build.make CMakeFiles/modeling_2014_framework.dir/depend
make[2]: Entering directory `/home/myname/courses/Modellierung/proj/exercise1'
cd /home/myname/courses/Modellierung/proj/exercise1 && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/myname/courses/Modellierung/proj/exercise1 /home/myname/courses/Modellierung/proj/exercise1 /home/myname/courses/Modellierung/proj/exercise1 /home/myname/courses/Modellierung/proj/exercise1 /home/myname/courses/Modellierung/proj/exercise1/CMakeFiles/modeling_2014_framework.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/myname/courses/Modellierung/proj/exercise1'
make -f CMakeFiles/modeling_2014_framework.dir/build.make CMakeFiles/modeling_2014_framework.dir/build
make[2]: Entering directory `/home/myname/courses/Modellierung/proj/exercise1'
Linking CXX executable modeling_2014_framework
/usr/bin/cmake -E cmake_link_script CMakeFiles/modeling_2014_framework.dir/link.txt --verbose=1
/usr/bin/g++   -g3 -gdwarf-2    CMakeFiles/modeling_2014_framework.dir/main.cpp.o CMakeFiles/modeling_2014_framework.dir/src/VertexBufferObjectAttribs.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Vector3.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Shader.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Matrix4x4.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Scene.cpp.o CMakeFiles/modeling_2014_framework.dir/src/TgaLoader.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Vector4.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Vector2.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Renderer.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Matrix3x3.cpp.o CMakeFiles/modeling_2014_framework.dir/src/Common.cpp.o CMakeFiles/modeling_2014_framework.dir/src/SkyCube.cpp.o  -o modeling_2014_framework -rdynamic -lGLU -lGL -lSM -lICE -lX11 -lXext -lGLEW -lglfw3 -lXxf86vm -lGLU -lX11 -lXrandr -lpthread -lXi 
/usr/bin/ld: error: cannot find -lglfw3
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:49: error: undefined reference to 'glfwInit'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:53: error: undefined reference to 'glfwInit'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:60: error: undefined reference to 'glfwSetErrorCallback'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:63: error: undefined reference to 'glfwWindowHint'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:64: error: undefined reference to 'glfwWindowHint'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:65: error: undefined reference to 'glfwWindowHint'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:66: error: undefined reference to 'glfwWindowHint'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:74: error: undefined reference to 'glfwCreateWindow'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:77: error: undefined reference to 'glfwSetKeyCallback'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:78: error: undefined reference to 'glfwSetWindowSizeCallback'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:79: error: undefined reference to 'glfwSetMouseButtonCallback'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:80: error: undefined reference to 'glfwSetCursorPosCallback'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:81: error: undefined reference to 'glfwSetScrollCallback'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:84: error: undefined reference to 'glfwMakeContextCurrent'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:164: error: undefined reference to 'glfwTerminate'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:170: error: undefined reference to 'glfwGetTime'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:171: error: undefined reference to 'glfwGetTime'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:189: error: undefined reference to 'glfwPollEvents'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:190: error: undefined reference to 'glfwSwapBuffers'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:192: error: undefined reference to 'glfwSetWindowTitle'
/home/myname/courses/Modellierung/proj/exercise1/main.cpp:186: error: undefined reference to 'glfwWindowShouldClose'
/home/myname/courses/Modellierung/proj/exercise1/src/Renderer.cpp:61: error: undefined reference to 'glfwGetTime'
/home/myname/courses/Modellierung/proj/exercise1/src/Renderer.cpp:64: error: undefined reference to 'glfwGetTime'
collect2: error: ld returned 1 exit status
make[2]: *** [modeling_2014_framework] Error 1
make[2]: Leaving directory `/home/myname/courses/Modellierung/proj/exercise1'
make[1]: *** [CMakeFiles/modeling_2014_framework.dir/all] Error 2
make[1]: Leaving directory `/home/myname/courses/Modellierung/proj/exercise1'
make: *** [all] Error 2
myname@fxt ~/courses/Modellierung/proj/exercise1 $ 

EDIT / QUICK HACK SOLUTION: I think this is not the real answer to the original problem, but at least I've found a workaround. I added

SET( CMAKE_EXE_LINKER_FLAGS   "-L/usr/local/lib")

to the CMakeLists.txt file, directly above add_executable(...)

Now it works, because the -L... option is correctly passed to the linker. However, since I've hardcoded the path this might not work on any computer.

Similar Question 6 (1 solutions) : undefined reference to `log'

Similar Question 9 (1 solutions) : ld cannot find library curl when running make file

cc