From Qt3 to Qt4 : issues with internal classes ( Q3GList & Q3PtrCollection ) - c++

I'm updating a code from Qt3 to Qt4. I used qt3to4 porting tool, and it fixed some of my issues. But a few errors are remaining:
g++ -m64 -Wl,-O1 -o CONVECTION_DYN_CODE_version_initiale Convection_points.o Convection_points_prof.o glbox.o globjwin.o main.o algebra.o evector.o matrix.o matrix4.o quaternion.o write_binary.o write_binary_normals.o moc_glbox.o moc_globjwin.o -L/usr/lib/x86_64-linux-gnu -L/usr/X11R6/lib64 -lQtOpenGL -lQtGui -lQtCore -lGLU -lglut -lGL -lpthread -lCGAL -fp-model -lboost_thread -lgmp
glbox.o:(.rodata._ZTI7Q3GList[typeinfo for Q3GList]+0x10): undefined reference to `typeinfo for Q3PtrCollection'
&
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x18): undefined reference to `Q3GList::clear()'
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x20): undefined reference to `Q3GList::~Q3GList()'
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x28): undefined reference to `Q3GList::~Q3GList()'
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x30): undefined reference to `Q3PtrCollection::newItem(void*)'
...
Both Q3GList and Q3PtrCollection are internal classes. I added the corresponding headers but I still got these errors. I don't know how to fix it since it seems to be internal issues.
Any ideas?

You should also link against qt3support module.
Add
QT += qt3support
to your project settings.

Related

How do I change the order in automake's CXXLINK?

I am trying to compile a simple C++ program with the automake tools. By itself, automake creates in its Makefile the line: CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ -o $#
This way, however, i get some linker errors, which can be resolved by simply putting the -o example example.cpp part in the beginning of the g++ command instead of the end.
How can I instruct automake to put the -o example example.cpp in front of the linker commands?
Here is the Makefile.am
bin_PROGRAMS = GLTest
GLTest_SOURCES = main.cpp
AM_CXXFLAGS=#gllibs_CFLAGS# -std=c++11 -pthread
AM_LDFLAGS=#gllibs_LIBS# -lGL -lGLEW -lglfw -lX11 -lXi -lXrandr
Here are the linker errors:
g++ -I/usr/include/libdrm -std=c++11 -pthread -g -O2 -lGLEW -lGLU -lGL -lglfw -lGL -lGLEW -lglfw -lX11 -lXi -lXrandr -o GLTest main.o
main.o: In function `main':
main.cpp:8: undefined reference to `glfwInit'
main.cpp:9: undefined reference to `glfwWindowHint'
main.cpp:10: undefined reference to `glfwWindowHint'
main.cpp:11: undefined reference to `glfwWindowHint'
main.cpp:12: undefined reference to `glfwWindowHint'
main.cpp:14: undefined reference to `glfwCreateWindow'
collect2: error: ld returned 1 exit status
These are resolved when I compile it manually like this:
g++ -o GLTest main.cpp -I/usr/include/libdrm -std=c++11 -pthread -g -O2 -lGLEW -lGLU -lGL -lglfw -lGL -lGLEW -lglfw -lX11 -lXi -lXrandr
You're doing it wrong. The problem is you're passing libraries as LDFLAGS, and that is incorrect.
You should have
GLTest_LDADD = $(gllibs_LIBS)
so that you're telling automake correctly that those are libraries.
Using libtool may work, depending on the libtool version used, since it can sort the command line, but it's still the wrong thing to do and fails in other situations.
From the linker command in the output it looks like you are not using libtool.
Try adding AM_PROG_LIBTOOL to the configure.ac.

Linker Error when compiling with static library [duplicate]

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 6 years ago.
I have a project with several .cpp and .h files, and I am trying to split the source into core / generic stuff, and application specific code. Based on that, I separated the code files into a Common folder and compiled it as a library. Below is the Makefile for that lib:
CFLAGS=-std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib
SOURCES = $(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
OUTPUTFILE=libcommon.a
all: $(OUTPUTFILE)
$(OUTPUTFILE): $(OBJECTS)
ar rcs $(OUTPUTFILE) $(OBJECTS)
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $# $(GPROF)
clean:
rm -f $(OBJECTS) $(OUTPUTFILE)
Then I created a sample main file just to try out the compilation of an app using that library.
Here is the code of the main source file:
#include "../Common/Functions.h"
#include "../Common/Logger.h"
int main() {
Logger::Init(false, false);
Logger::Debug("Test");
string path = Functions::GetAppPath();
Logger::Debug("App Path: ", path.c_str());
return 0;
}
The functions file that is being referenced uses boost, and here is the makefile for this app that uses the library:
CC=g++
CFLAGS=-Wl,--verbose -std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib
LDFLAGS=-I../boost_1_57_0 -L../boost_1_57_0/stage/lib -L../boost_libs/lib -L/usr/lib64 -L/usr/kerberos/lib -L/usr/lib -L../Common
LIBS=-lz -lkrb5 -lk5crypto -lcom_err -lresolv -lm -lpthread -lrt -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -rdynamic -lcurl -lcommon
SOURCES = $(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=testApp
GPROF=-pg
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $# $(LIBS) $(GPROF)
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $# $(GPROF)
clean:
rm -rf *o $(OBJECTS)
When I try to compile, I get the following errors, complaining about undefined references to boost:
g++ -Wl,--verbose -std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib main.cpp -o main.o -pg
g++ -I../boost_1_57_0 -L../boost_1_57_0/stage/lib -L../boost_libs/lib -L/usr/lib64 -L/usr/kerberos/lib -L/usr/lib -L../Common main.o -o testApp -lz -lkrb5 -lk5crypto -lcom_err -lresolv -lm -lpthread -lrt -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -rdynamic -lcurl -lcommon -pg
../Common/libcommon.a(Functions.o): In function `Functions::GetAppPath()':
/media/software/Robots/Common/Functions.cpp:43: undefined reference to `boost::filesystem::path::parent_path() const'
../Common/libcommon.a(Functions.o): In function `boost::filesystem::initial_path()':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:583: undefined reference to `boost::filesystem::detail::initial_path(boost::system::error_code*)'
../Common/libcommon.a(Functions.o): In function `boost::filesystem::system_complete(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:655: undefined reference to `boost::filesystem::detail::system_complete(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Functions.o): In function `unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::string const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/date_time/date_parsing.hpp:67: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'
../Common/libcommon.a(Logger.o): In function `Logger::Cleanup()':
/media/software/Robots/Common/Logger.cpp:84: undefined reference to `boost::thread::interrupt()'
../Common/libcommon.a(Logger.o): In function `Logger::InitFile(std::string, bool, std::_Ios_Openmode)':
/media/software/Robots/Common/Logger.cpp:186: undefined reference to `boost::filesystem::path::parent_path() const'
/media/software/Robots/Common/Logger.cpp:187: undefined reference to `boost::filesystem::path::parent_path() const'
../Common/libcommon.a(Logger.o): In function `Logger::Process()':
/media/software/Robots/Common/Logger.cpp:241: undefined reference to `boost::this_thread::interruption_point()'
../Common/libcommon.a(Logger.o): In function `boost::detail::thread_data_base::thread_data_base()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/pthread/thread_data.hpp:143: undefined reference to `vtable for boost::detail::thread_data_base'
../Common/libcommon.a(Logger.o): In function `boost::thread::start_thread()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:179: undefined reference to `boost::thread::start_thread_noexcept()'
../Common/libcommon.a(Logger.o): In function `boost::thread::~thread()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:254: undefined reference to `boost::thread::detach()'
../Common/libcommon.a(Logger.o): In function `boost::thread::get_id() const':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:741: undefined reference to `boost::thread::native_handle()'
../Common/libcommon.a(Logger.o): In function `boost::thread::join()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:767: undefined reference to `boost::thread::join_noexcept()'
../Common/libcommon.a(Logger.o): In function `boost::filesystem::exists(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:404: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Logger.o): In function `boost::filesystem::create_directories(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:523: undefined reference to `boost::filesystem::detail::create_directories(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Logger.o): In function `boost::detail::thread_data<void (*)()>::~thread_data()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:90: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
../Common/libcommon.a(Logger.o):(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[_ZTIN5boost6detail11thread_dataIPFvvEEE]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: error: ld returned 1 exit status
Needless to say that the project as a whole compiles with no issue.
This is my first attempt at building a c++ linux library and using it in another application, so I might be doing a rookie mistake, so bear that in mind.
Help is very much appreciated.
Thank you.
The order of libraries on the command line is significant to the linker. It processes libraries from left to right, resolving as-yet unresolved references already known to it against any functions provided by the current library.
Moreover, and particularly relevant here, if a given library contains references to functions that it does not itself provide then the linker does not resolve those against libraries it has already processed. That's why you have unresolved references: you have -lcommon last among your libraries, so function references therein will be resolved against only the C standard library.
It is valid to list libraries more than once in the link command, and sometimes that is needed, but in this case I think it makes sense simply to put -lcommon as the first library instead of the last. That will resolve the issue. You can even conceptualize this as putting the library most closely related to the main program closest to it in the link command.

FreeGLUT linking Issues in Linux

I am running Linux Mint 14.1 64-bit
I have installed the following libs:
mesa-common-dev,
freeglut3-dev,
libglew-dev
through the apt-get tool.
Here are my includes, located in my Main.h file:
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <time.h>
I checked that the libs installed correctly, they seem to be located in /usr/lib/x86_64-linux-gnu
and the headers in /usr/include/GL
I proceed to compile my Main.C file with the following flags:
g++ -Wall -Wextra -Weffc++ -Winit-self -Wmissing-include-dirs -Wswitch-default -switch-enum -Wunused-parameter -Wstrict-overflow=5 -Wfloat-equal -Wshadow -Wc++0x-compat -Wconversion -Wsign-conversion -Wmissing-declarations -Wstrict-null-sentinel -Woverloaded-virtual -Wsign-promo -Werror -pedantic -Wcast-qual -fno-pretty-templates -fmessage-length=80 -fdiagnostics-show-option -g -std=c++0x -pipe -frepo -c Main.C -o Main.o
Main.o is generated without any issues, then I try to create the binary:
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng Main.o -o main
And receive the following errors:
Main.o: In function `init()':
/path/to/Main.C:12: undefined reference to `glClearColor'
Main.o: In function `initGLUT(int, char**)':
/path/to/Main.C: undefined reference to `glutInit'
/path/to/Main.C:21: undefined reference to `glutInitDisplayMode'
/path/to/Main.C:24: undefined reference to `glutInitWindowSize'
/path/to/Main.C:25: undefined reference to `glutCreateWindow'
/path/to/Main.C:28: undefined reference to `glutDisplayFunc'
/path/to/Main.C:31: undefined reference to `glutKeyboardFunc'
/path/to/Main.C:34: undefined reference to `glutMouseFunc'
/path/to/Main.C:37: undefined reference to `glutReshapeFunc'
/path/to/Main.C:40: undefined reference to `glutIdleFunc'
Main.o: In function `printFPS()':
/path/to/Main.C:96: undefined reference to `glutGet'
Main.o: In function `reshape(int, int)':
/path/to/Main.C:123: undefined reference to `glutPostRedisplay'
Main.o: In function `getTime()':
/path/to/Main.C:129: undefined reference to `glutGet'
Main.o: In function `idle()':
/path/to/Main.C:141: undefined reference to `glutPostRedisplay'
Main.o: In function `display()':
/path/to/Main.C:148: undefined reference to `glClearColor'
/path/to/Main.C:149: undefined reference to `glClear'
/path/to/Main.C:150: undefined reference to `glFlush'
/path/to/Main.C:151: undefined reference to `glutSwapBuffers'
Main.o: In function `main':
/path/to/Main.C:164: undefined reference to `glutMainLoop'
The program compiles and links on another Linux system though.
what could I be missing?
You have to pass the libraries last (after the object file)
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu Main.o \
-lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng -o main
The reason behind this is, that the linker only links symbols, that are currently undefined. If you pass the libraries before the object files, then there aren't any undefined symbols to be linked and compilation/linking will therefore fail.
The libraries need to come after your object files:
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu Main.o -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng -o main

OpenCV LDFlags linking issue

I am compiling a program with the following flags and getting errors (running 64 bit os):
g++ -lm -lml -lcvaux -lhighgui -lcv -lcxcore main.o BRIEF.o -o BRIEF_demo
I get a bunch of undefined references:
main.cpp:(.text+0x1f6): undefined reference to `cvInitMatHeader'
main.cpp:(.text+0x218): undefined reference to cvInitMatHeader'
main.o: In function_Z14drawQuadrangleP9_IplImageiiiiiiii8CvScalari.constprop.77':
main.cpp:(.text+0x2d5): undefined reference to cvLine'
main.cpp:(.text+0x333): undefined reference tocvLine'
main.cpp:(.text+0x398): undefined reference to cvLine'
main.cpp:(.text+0x3f2): undefined reference tocvLine'
Anyone have an idea how to circumvent this?
I suppose you are using the newest OpenCV 2.3.x. cvInitMatHeader() and cvLine() are actually defined in libcxcore.so, which I can see you are including.
My guess is that the order of the linking is wrong, so you need to adjust your command to something like:
g++ main.cpp BRIEF.cpp -o BRIEF_demo -lm -lml -lcvaux -lhighgui -lcv -lcxcore

Boost.Asio installation issue

i have already installed boost libraries with bjam install, but when i'm compiling programme:
#include boost/asio.hpp
int main()
{
return 0;
}
such errors occur:
/tmp/ccVR3eeF.o: In function `__static_initialization_and_destruction_0(int, int)':
sda.cpp:(.text+0x52): undefined reference to `boost::system::generic_category()'
sda.cpp:(.text+0x5e): undefined reference to `boost::system::generic_category()'
sda.cpp:(.text+0x6a): undefined reference to `boost::system::system_category()'
/tmp/ccVR3eeF.o: In function `boost::asio::error::get_system_category()':
sda.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x5): undefined reference to `boost::system::system_category()'
/tmp/ccVR3eeF.o: In function `boost::asio::detail::posix_tss_ptr_create(unsigned int&)':
sda.cpp:(.text._ZN5boost4asio6detail20posix_tss_ptr_createERj[boost::asio::detail::posix_tss_ptr_create(unsigned int&)]+0x19): undefined reference to `pthread_key_create'
/tmp/ccVR3eeF.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service>::context>::~posix_tss_ptr()':
sda.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceEE7contextEED2Ev[boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service>::context>::~posix_tss_ptr()]+0x15): undefined reference to `pthread_key_delete'
/tmp/ccVR3eeF.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl>::context>::~posix_tss_ptr()':
sda.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEE7contextEED2Ev[boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl>::context>::~posix_tss_ptr()]+0x15): undefined reference to `pthread_key_delete'
collect2: ld returned 1 exit status
what do i have to do? how can i build those libraries?
Boost.Asio requires the Boost.System library as well; you need to add -lboost_system to your linker command line.
As you add features to your program, you might also need other parts of Boost, like Boost.Thread, Boost.Date_Time, and so on. See http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/using.html for details.
I use netbeans so i typed '-lboost_system' in additional lines ! That was a mistake.
Additional lines are put before objects, and because of that i had the same error. Then i found out if i run from console and put -lboost_system at the VERY END everything works greate. At the end i found the right place to set in netbeans (in library not command section) and that field adds it at the end!
Remember, not only counts if you have the library in command ! THE POSITION does count :) Remember to put library at end and verify it :)
Work great:
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -c -g -MMD -MP -MF async_client.o.d -o async_client.o async_client.cpp
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -o async_client async_client.o -lws2_32 -lboost_chrono -lboost_system -lboost_thread
Doesn't work:
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -c -g -MMD -MP -MF async_client.o.d -o async_client.o async_client.cpp
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -lws2_32 -lboost_chrono -lboost_system -lboost_thread -o async_client async_client.o