Iam learning boost and test some examples, so I link boost libraries in my QT project with MinGW compiler, and I want to link all the libraries so i can use anything from filesystem to asio and go with different examples that use many classes.
this my .pro file which I link the boost libraries
INCLUDEPATH += C:/boost_1_66_0
LIBS += -LC:/boost_1_66_0/stage/lib -llibboost_atomic-mgw63-mt-d-x32-1_66\
-llibboost_atomic-mgw63-mt-x32-1_66\
-llibboost_chrono-mgw63-mt-d-x32-1_66\
-llibboost_chrono-mgw63-mt-x32-1_66\
-llibboost_container-mgw63-mt-d-x32-1_66\
-llibboost_container-mgw63-mt-x32-1_66\
-llibboost_context-mgw63-mt-d-x32-1_66\
-llibboost_context-mgw63-mt-x32-1_66\
-llibboost_coroutine-mgw63-mt-d-x32-1_66\
-llibboost_coroutine-mgw63-mt-x32-1_66\
-llibboost_date_time-mgw63-mt-d-x32-1_66\
-llibboost_date_time-mgw63-mt-x32-1_66\
-llibboost_exception-mgw63-mt-d-x32-1_66\
-llibboost_exception-mgw63-mt-x32-1_66\
-llibboost_filesystem-mgw63-mt-d-x32-1_66\
-llibboost_filesystem-mgw63-mt-x32-1_66\
-llibboost_graph-mgw63-mt-d-x32-1_66\
-llibboost_graph-mgw63-mt-x32-1_66\
-llibboost_iostreams-mgw63-mt-d-x32-1_66\
-llibboost_iostreams-mgw63-mt-x32-1_66\
-llibboost_locale-mgw63-mt-d-x32-1_66\
-llibboost_locale-mgw63-mt-x32-1_66\
-llibboost_log-mgw63-mt-d-x32-1_66\
-llibboost_log-mgw63-mt-x32-1_66\
-llibboost_log_setup-mgw63-mt-d-x32-1_66\
-llibboost_log_setup-mgw63-mt-x32-1_66\
-llibboost_math_c99-mgw63-mt-d-x32-1_66\
-llibboost_math_c99-mgw63-mt-x32-1_66\
-llibboost_math_c99f-mgw63-mt-d-x32-1_66\
-llibboost_math_c99f-mgw63-mt-x32-1_66\
-llibboost_math_c99l-mgw63-mt-d-x32-1_66\
-llibboost_math_c99l-mgw63-mt-x32-1_66\
-llibboost_math_tr1-mgw63-mt-d-x32-1_66\
-llibboost_math_tr1-mgw63-mt-x32-1_66\
-llibboost_math_tr1f-mgw63-mt-d-x32-1_66\
-llibboost_math_tr1f-mgw63-mt-x32-1_66\
-llibboost_math_tr1l-mgw63-mt-d-x32-1_66\
-llibboost_math_tr1l-mgw63-mt-x32-1_66\
-llibboost_prg_exec_monitor-mgw63-mt-d-x32-1_66\
-llibboost_prg_exec_monitor-mgw63-mt-x32-1_66\
-llibboost_program_options-mgw63-mt-d-x32-1_66\
-llibboost_program_options-mgw63-mt-x32-1_66\
-llibboost_random-mgw63-mt-d-x32-1_66\
-llibboost_random-mgw63-mt-x32-1_66\
-llibboost_regex-mgw63-mt-d-x32-1_66\
-llibboost_regex-mgw63-mt-x32-1_66\
-llibboost_serialization-mgw63-mt-d-x32-1_66\
-llibboost_serialization-mgw63-mt-x32-1_66\
-llibboost_signals-mgw63-mt-d-x32-1_66\
-llibboost_signals-mgw63-mt-x32-1_66\
-llibboost_stacktrace_basic-mgw63-mt-d-x32-1_66\
-llibboost_stacktrace_basic-mgw63-mt-x32-1_66\
-llibboost_stacktrace_noop-mgw63-mt-d-x32-1_66\
-llibboost_stacktrace_noop-mgw63-mt-x32-1_66\
-llibboost_system-mgw63-mt-d-x32-1_66\
-llibboost_system-mgw63-mt-x32-1_66\
-llibboost_test_exec_monitor-mgw63-mt-d-x32-1_66\
-llibboost_test_exec_monitor-mgw63-mt-x32-1_66\
-llibboost_thread-mgw63-mt-d-x32-1_66\
-llibboost_thread-mgw63-mt-x32-1_66\
-llibboost_timer-mgw63-mt-d-x32-1_66\
-llibboost_timer-mgw63-mt-x32-1_66\
-llibboost_type_erasure-mgw63-mt-d-x32-1_66\
-llibboost_type_erasure-mgw63-mt-x32-1_66\
-llibboost_unit_test_framework-mgw63-mt-d-x32-1_66\
-llibboost_unit_test_framework-mgw63-mt-x32-1_66\
-llibboost_wave-mgw63-mt-d-x32-1_66\
-llibboost_wave-mgw63-mt-x32-1_66\
-llibboost_wserialization-mgw63-mt-d-x32-1_66\
-llibboost_wserialization-mgw63-mt-x32-1_66\
I go to the boost lib folder and add all the libraries as above, I start now testing some functions and I still got undefine refernce to some functions although I linked all the libararies and I use it in Release mode here is my main in which i use boost archive
#include <fstream>
#include <ios>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <locale>
#include <codecvt>
#include <cstring>
#include <boost/archive/text_oarchive.hpp>
using namespace boost::archive;
using namespace std;
int main(int argc, char *argv[])
{
ofstream out("D:/a.txt");
text_oarchive oa(out);
int a = INT_MAX;
oa << a;
out.close();
return 0;
}
this is the error I got
release/main.o:main.cpp:(.text.startup+0xf1): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_14object_id_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_14object_id_typeE]+0x69): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_21object_reference_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_21object_reference_typeE]+0x62): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13class_id_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13class_id_typeE]+0x63): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_23class_id_reference_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_23class_id_reference_typeE]+0x63): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13tracking_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13tracking_typeE]+0x63): more undefined references to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)' follow
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Release:63: release/Normal2.exe] Error 1
mingw32-make: *** [Makefile:36: release] Error 2
mingw32-make[1]: Leaving directory 'D:/WorkPlace/CppProject/cpp/build-Normal2-Desktop_QT_5_12_0_MinGW_32_bit-Release'
17:41:30: The process "C:\Qt\Qt5.12.0\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project Normal2 (kit: Desktop QT 5.12.0 MinGW 32-bit)
When executing step "Make"
17:41:30: Elapsed time: 00:04.
so what mistake i made to give me those erros, and I already linked all the libraries and add them to my Project i did not test more examples yet so i don't know if I will got some errors more if i used different classes.
Iam using this website to learn more about boost library here so I am going with different examples to test and I need to link all boost libraries
Update
This now my .pro file i removed the lib at the beggining and I remove debug libraries and use only release here is my .pro file
LIBS += -LC:/boost_1_66_0/stage/lib -lboost_atomic-mgw63-mt-x32-1_66\
-lboost_chrono-mgw63-mt-x32-1_66\
-lboost_container-mgw63-mt-x32-1_66\
-lboost_context-mgw63-mt-x32-1_66\
-lboost_coroutine-mgw63-mt-x32-1_66\
-lboost_date_time-mgw63-mt-x32-1_66\
-lboost_exception-mgw63-mt-x32-1_66\
-lboost_filesystem-mgw63-mt-x32-1_66\
-lboost_graph-mgw63-mt-x32-1_66\
-lboost_iostreams-mgw63-mt-x32-1_66\
-lboost_locale-mgw63-mt-x32-1_66\
-lboost_log-mgw63-mt-x32-1_66\
-lboost_log_setup-mgw63-mt-x32-1_66\
-lboost_math_c99-mgw63-mt-x32-1_66\
-lboost_math_c99f-mgw63-mt-x32-1_66\
-lboost_math_c99l-mgw63-mt-x32-1_66\
-lboost_math_tr1-mgw63-mt-x32-1_66\
-lboost_math_tr1f-mgw63-mt-x32-1_66\
-lboost_math_tr1l-mgw63-mt-x32-1_66\
-lboost_prg_exec_monitor-mgw63-mt-x32-1_66\
-lboost_program_options-mgw63-mt-x32-1_66\
-lboost_random-mgw63-mt-x32-1_66\
-lboost_regex-mgw63-mt-x32-1_66\
-lboost_serialization-mgw63-mt-x32-1_66\
-lboost_signals-mgw63-mt-x32-1_66\
-lboost_stacktrace_basic-mgw63-mt-x32-1_66\
-lboost_stacktrace_noop-mgw63-mt-x32-1_66\
-lboost_system-mgw63-mt-x32-1_66\
-lboost_test_exec_monitor-mgw63-mt-x32-1_66\
-lboost_thread-mgw63-mt-x32-1_66\
-lboost_timer-mgw63-mt-x32-1_66\
-lboost_type_erasure-mgw63-mt-x32-1_66\
-lboost_unit_test_framework-mgw63-mt-x32-1_66\
-lboost_wave-mgw63-mt-x32-1_66\
-lboost_wserialization-mgw63-mt-x32-1_66\
but still the same problem, if the order matter what order i need to make this example work?, also if there is a way to add them all at once with a right order it will be better.
Thanks in advance.
Related
I have created a project with intention of using hunspell functions in it. I am working in Ubuntu. I installed and compiled hunspell library and linked it with g++ -o wc.exe -lhunspell-1.6 wordcheck.cxx and everything seemed ok. But when I tried to compile and launch my project I got some errors.
#include <iostream>
#include "hunspell/hunspell.hxx"
using namespace std;
int main(int argc,char** argv)
{
FILE* lst=fopen("wordlist.txt","r");
if(!lst)
{
cerr<<"Can not open file\n";
return 1;
}
Hunspell* hs=new Hunspell(argv[1],argv[2]);
delete hs;
return 0;
}
and the errors were:
/home/alex2/Документы/bO/wordcheck.cxx:14: undefined reference to Hunspell::Hunspell(char const*, char const*, char const*)'
/home/alex2/Документы/bO/wordcheck.cxx:15: undefined reference toHunspell::~Hunspell()'
collect2: error: ld returned 1 exit status
atus
I have no idea what is wrong. I tried using
Hunspell* hs=new Hunspell();
and got that there is a candidate for it that requires three parameters:
/usr/local/include/hunspell/hunspell.hxx:115:3: note: candidate: Hunspell::Hunspell(const char*, const char*, const char*)
Hunspell(const char* affpath, const char* dpath, const char* key = NULL);
The only difference is char const* and const char* but I always thought it is the same thing. The entire project is similar to the example file hunspell provides and I have no idea what am I doing wrong and why my thing is not working.
I'm trying to port over a game that I made using Allegro 5.0 (from Windows to a Raspberry Pi running Raspian). I installed Allegro and moved over all my source files, but when I try to compile using: *g++ -std=c++0x .cpp -o SpaceFighter $(pkg-config --libs allegro-5) I get the following:
/tmp/ccBliSky.o: In function main':
main.cpp:(.text+0x130): undefined reference toal_show_native_message_box'
main.cpp:(.text+0x160): undefined reference to al_init_font_addon'
main.cpp:(.text+0x164): undefined reference toal_init_ttf_addon'
main.cpp:(.text+0x168): undefined reference to al_init_image_addon'
main.cpp:(.text+0x1a4): undefined reference toal_load_ttf_font'
main.cpp:(.text+0x574): undefined reference to al_draw_textf'
/tmp/ccBMyqom.o: In functionMenuItem::MenuItem()':
MenuItem.cpp:(.text+0xa0): undefined reference to al_load_ttf_font'
/tmp/ccBMyqom.o: In functionMenuItem::~MenuItem()':
MenuItem.cpp:(.text+0x1ac): undefined reference to al_destroy_font'
/tmp/ccBMyqom.o: In functionMenuItem::Draw(GameTime const*)':
MenuItem.cpp:(.text+0x2fc): undefined reference to al_draw_text'
/tmp/ccKXP3ds.o: In functionPlayerShip::SetAudioSample(std::string)':
PlayerShip.cpp:(.text+0x604): undefined reference to al_destroy_sample'
PlayerShip.cpp:(.text+0x64c): undefined reference toal_load_sample'
collect2: error: ld returned 1 exit status
AND NO THIS IS NOT A DUPLICATE OF "What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them?"
I know what usually causes most undefined reference errors. This question is specific to the allegro library I'm using.
Here's a bit of code (I'm obviously not going to post the whole game):
#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_image.h>
#include <iostream>
#include "Game.h"
int main(int argc, char *argv[])
{
const char errorType[] = "Initialization Error";
const int flags = ALLEGRO_MESSAGEBOX_ERROR;
// Initialize Allegro
if (!al_init())
{
const char message[] = "Failed to initialize Allegro Library.";
//al_show_native_message_box(nullptr, "Error", errorType, message, nullptr, flags);
return -1;
}
Game game;
// Initialize a new window for gameplay.
int screenWidth = Game::GetScreenWidth();
int screenHeight = Game::GetScreenHeight();
Thanks in advance for any help!
Alegro divides its functionality across several modules. Your pkg-config line must include all the modules you are using. Try the following:
pkg-config --libs allegro-5 allegro_font-5 allegro_image-5 allegro_ttf-5
I had the same problem with the al_show_native_message_box function and I solved it by adding the following flag:
-lallegro_dialog
Here's my includes:
#include <iostream>
#include <string>
#include <cstring>
#include <stdio.h> //for snprintf
#include <libscrypt.h>
#include <sqlite3.h>
#include "generator.h" //has no dependencies
And here's my g++ 4.2.1 command with compilation errors:
# g++ -I/usr/local/include -L /usr/local/lib test.cpp generator.cpp -o test -lscrypt -lsqlite3
/tmp//cctxmw4C.o: In function `insertUser()':
test.cpp:(.text+0x607): undefined reference to `libscrypt_salt_gen(unsigned char*, unsigned long)'
test.cpp:(.text+0x6c3): undefined reference to `libscrypt_scrypt(unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned long long, unsigned int, unsigned int, unsigned char*, unsigned long)'
collect2: ld returned 1 exit status
Similar C code compiles fine with GCC. I do not believe that the order of the parameters is the problem -- I have tried multiple variations, including moving the -I, -L, and both -l flags. Both scrypt and sqlite3 are C libraries, and sqlite3 throws no errors despite having the header and shared library in -I and -L respectively.
Look at the solution here.
Using C Libraries for C++ Programs
extern "C"{
void c_function_prototype();
}
or
extern "C" void c_function_prototype();
If you have it see "The C++ Programming Language (Stoustrup) 4th Edition" p429
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.
I'm trying to run this code using c++11 std::thread and the SFML library for networking, however I just cant get it to build. I'm pretty sure it has something to do with how I'm setting up the compiler, but I don't know... How can I get this to work? I've been messing about trying to get this to work, going through tutorials and such for hours now, so I have turned to Stack Overflow for answers. I'm using the code::blocks IDE and the x32-4.8.1-posix-dwarf-rev5 compiler on a windows7 64-bit machine.
#include <iostream>
#include <thread>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
using namespace std;
void doNetwork() {
cout << "Starting..." << endl;
sf::TcpListener listener;
listener.listen(88);
// Wait for a connection
sf::TcpSocket socket;
listener.accept(socket);
cout << "New client connected: " << socket.getRemoteAddress() << endl;
// Receive a message from the client
char buffer[1024];
size_t received = 0;
socket.receive(buffer, sizeof(buffer), received);
cout << "The client said: " << buffer << endl;
// Send an answer
string message = "Welcome, client";
socket.send(message.c_str(), message.size() + 1);
}
int main()
{
thread task(doNetwork);
task.join();
return 0;
}
This is what the build debug log is saying:
-------------- Build: Debug in bang ---------------
Compiling: main.cpp
Linking console executable: bin\Debug\bang.exe
obj\Debug\main.o: In function `Z9doNetworkv':
C:/Users/user/CppProjects/bang/main.cpp:12: undefined reference to `sf::TcpListener::TcpListener()'
C:/Users/user/CppProjects/bang/main.cpp:13: undefined reference to `sf::TcpListener::listen(unsigned short)'
C:/Users/user/CppProjects/bang/main.cpp:16: undefined reference to `sf::TcpSocket::TcpSocket()'
C:/Users/user/CppProjects/bang/main.cpp:17: undefined reference to `sf::TcpListener::accept(sf::TcpSocket&)'
C:/Users/user/CppProjects/bang/main.cpp:18: undefined reference to `sf::TcpSocket::getRemoteAddress() const'
C:/Users/user/CppProjects/bang/main.cpp:18: undefined reference to `sf::operator<<(std::ostream&, sf::IpAddress const&)'
C:/Users/user/CppProjects/bang/main.cpp:23: undefined reference to `sf::TcpSocket::receive(void*, unsigned int, unsigned int&)'
C:/Users/user/CppProjects/bang/main.cpp:28: undefined reference to `sf::TcpSocket::send(void const*, unsigned int)'
obj\Debug\main.o: In function `ZN2sf11TcpListenerD1Ev':
C:/Users/user/CppProjects/SFML-2.1/include/SFML/Network/TcpListener.hpp:43: undefined reference to `sf::Socket::~Socket()'
obj\Debug\main.o: In function `ZN2sf9TcpSocketD1Ev':
C:/Users/user/CppProjects/SFML-2.1/include/SFML/Network/TcpSocket.hpp:46: undefined reference to `sf::Socket::~Socket()'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
10 errors, 0 warnings
The settings I am using with the compiler:
Compiler Flags:
-std=C++0x
Other options:
-std=gnu++0x -U__STRICT_ANSI__
defines:
SFML_STATIC
Linker Settings:
sfml-system-s-d
sfml-network-s-d
Search Directories - Compiler:
C:\Users\user\CppProjects\SFML-2.1\include
C:\Users\user\CppProjects\bang\include
Search Directories - Linker:
C:\Users\user\CppProjects\SFML-2.1\lib\
Toolchain Executables:
-Compilers instalation dir:
C:\Program Files (x86)\mingw-builds\x32-4.8.1-posix-dwarf-rev5\mingw32
-C compiler:
i686-w64-mingw32-gcc-4.8.1.exe
-C++ Compiler:
i686-w64-mingw32-c++.exe
-Linker for dynamic libs:
i686-w64-mingw32-c++.exe
-Linker for static libs:
ar.exe
-Debugger:
gdb.exe
-Resource Compiler:
windres.exe
-Make Program:
mingw32-make.exe
I had a simular problem and how i solved this on a Linux system was: Project / build options
Go to linker settings tab.
there i added: sfml-network
Done.
Hope it helps