I made a project that is using SFML library on linux, it's working pretty fine. I start it by launching this script exec.sh:
g++ -c main.cpp -I/usr/include
g++ main.o -o sfml-app -L/usr/lib -lsfml-graphics -lsfml-window -lsfml-system
export LD_LIBRARY_PATH=/usr/lib && ./sfml-app
And here is the code de in the main.cpp file:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Blue);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
But the problem is that i can't debug it and i always have an error when trying it. Can someone give me an advice or explain how can i properly do it? I need the solution exactly for linux, i'm a newbie in this OC and IDE.
Here's the ERROR, after debugging using g++:
Starting build...
Build finished with error:
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `main':
/home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::String::String(char const*, std::locale const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:6: undefined reference to `sf::CircleShape::CircleShape(float, unsigned long)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Color::Blue'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:9: undefined reference to `sf::Window::isOpen() const'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:12: undefined reference to `sf::Window::pollEvent(sf::Event&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:15: undefined reference to `sf::Window::close()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderStates::Default'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:20: undefined reference to `sf::Window::display()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `sf::CircleShape::~CircleShape()':
/usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status
Try installing library to your system path.
For Arch based Linux -
sudo pacman -S sfml
For Debian based Linux -
sudo apt-get install sfml-dev
And just use following g++ command -
g++ -c main.cpp -o main.o
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
It is better to use a IDE for it. You can use
Code Blocks
Code Lite
Apache netbeans
Eclipse
And if you are familiar with cmake you can use-
Kdevelop
Related
This question already has an answer here:
Linking issue with GCC 4.6.1
(1 answer)
Closed 1 year ago.
I wanted to build a gtest project on linux using just a makefile, ie not using cmake. I followed along the tutorial here:
http://www.yolinux.com/TUTORIALS/Cpp-GoogleTest.html
But getting multiple definition of main errors - see below.
I am on ubuntu v20.04
angus#angus-VirtualBox:~/Documents/code/gtest_make_only/test/src$ uname -a
Linux angus-VirtualBox 5.11.0-38-generic #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
I installed gtest like this:
git clone https://github.com/google/googletest.git
mkdir build
cd build
sudo snap install cmake --classic
cmake .. -DBUILD_GMOCK=OFF
make
sudo make install
If I now look on my system I have
/usr/local/include - with gtest directory with header files
/usr/local/lib - contains libgtest.a and libgtest_main.a
I modified the Makefile in the example to be like this:
CXX = g++
CXXFLAGS = -g -L/usr/local/lib -lgtest -lgtest_main -lpthread
INCS = -I./ -I../../src -I/usr/local/include
OBJS = ../../src/Addition.o Addition_Test.o ../../src/Multiply.o Multiply_Test.o
testAll: $(OBJS)
$(CXX) $(CXXFLAGS) $(INCS) -o testAll Main_TestAll.cpp $(OBJS)
.cpp.o:
$(CXX) $(CXXFLAGS) -c $< -o $# $(INCS)
clean:
rm testAll *.o testAll.xml
I also had to tidy up the code sample - eg where in code has Addition.h - have to change to Addition.hpp which is the filename.
The build error below. How to fix this?
I did try by removing -lgtest_main from the Makefile, but then get error:
/home/angus/Documents/code/gtest_make_only/test/src/Main_TestAll.cpp:5: undefined reference to `testing::InitGoogleTest(int*, char**)'
build error:
angus#angus-VirtualBox:~/Documents/code/gtest_make_only/test/src$ make
g++ -g -L/usr/local/lib -lgtest -lgtest_main -lpthread -c Multiply_Test.cpp -o Multiply_Test.o -I./ -I../../src -I/usr/local/include
g++ -g -L/usr/local/lib -lgtest -lgtest_main -lpthread -I./ -I../../src -I/usr/local/include -o testAll Main_TestAll.cpp ../../src/Addition.o Addition_Test.o ../../src/Multiply.o Multiply_Test.o
/usr/bin/ld: /tmp/cc4xkhF1.o: in function `RUN_ALL_TESTS()':
/home/angus/Documents/code/gtest_make_only/test/src/Main_TestAll.cpp:4: multiple definition of `main'; /usr/local/lib/libgtest_main.a(gtest_main.cc.o):gtest_main.cc:(.text+0x0): first defined here
/usr/bin/ld: /usr/local/lib/libgtest_main.a(gtest_main.cc.o): in function `main':
gtest_main.cc:(.text+0x3a): undefined reference to `testing::InitGoogleTest(int*, char**)'
/usr/bin/ld: /usr/local/lib/libgtest_main.a(gtest_main.cc.o): in function `RUN_ALL_TESTS()':
gtest_main.cc:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x9): undefined reference to `testing::UnitTest::GetInstance()'
/usr/bin/ld: gtest_main.cc:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x11): undefined reference to `testing::UnitTest::Run()'
/usr/bin/ld: /tmp/cc4xkhF1.o: in function `main':
/home/angus/Documents/code/gtest_make_only/test/src/Main_TestAll.cpp:5: undefined reference to `testing::InitGoogleTest(int*, char**)'
/usr/bin/ld: Addition_Test.o: in function `AdditionTest_twoValues_Test::TestBody()':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: Addition_Test.o: in function `__static_initialization_and_destruction_0(int, int)':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:16: undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/usr/bin/ld: Addition_Test.o: in function `testing::internal::SuiteApiResolver<AdditionTest>::GetSetUpCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Addition_Test.o: in function `testing::internal::SuiteApiResolver<AdditionTest>::GetTearDownCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Addition_Test.o: in function `testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)':
/usr/local/include/gtest/gtest.h:1549: undefined reference to `testing::AssertionSuccess()'
/usr/bin/ld: Addition_Test.o: in function `testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&)':
/usr/local/include/gtest/gtest.h:1532: undefined reference to `testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/bin/ld: Addition_Test.o: in function `AdditionTest::~AdditionTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:5: undefined reference to `testing::Test::~Test()'
/usr/bin/ld: Addition_Test.o:(.data.rel.ro._ZTI12AdditionTest[_ZTI12AdditionTest]+0x10): undefined reference to `typeinfo for testing::Test'
/usr/bin/ld: Addition_Test.o: in function `AdditionTest::AdditionTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:5: undefined reference to `testing::Test::Test()'
/usr/bin/ld: Multiply_Test.o: in function `MultiplyTest_twoValues_Test::TestBody()':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: Multiply_Test.o: in function `__static_initialization_and_destruction_0(int, int)':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:14: undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/usr/bin/ld: Multiply_Test.o: in function `testing::internal::SuiteApiResolver<MultiplyTest>::GetSetUpCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Multiply_Test.o: in function `testing::internal::SuiteApiResolver<MultiplyTest>::GetTearDownCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Multiply_Test.o: in function `MultiplyTest::~MultiplyTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:5: undefined reference to `testing::Test::~Test()'
/usr/bin/ld: Multiply_Test.o:(.data.rel.ro._ZTI12MultiplyTest[_ZTI12MultiplyTest]+0x10): undefined reference to `typeinfo for testing::Test'
/usr/bin/ld: Multiply_Test.o: in function `MultiplyTest::MultiplyTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:5: undefined reference to `testing::Test::Test()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:7: testAll] Error 1
Your command lines are all wrong.
Library specification should follow sources and object files. Correct line should look like this:
g++ -g -I./ -I../../src -o testAll Main_TestAll.cpp ../../src/Addition.o Addition_Test.o ../../src/Multiply.o Multiply_Test.o -lgtest_main -lgtest -lpthread
See this blog post for explanation.
Hi guys I have a project in QT5 which must connect to a mariadb server using C ++, the problem is that when compiling with qmake it returns several undefined reference errors with everything related to :: sql.
:-1: error: main.o: in function `printContacts(std::shared_ptr<sql::Statement>&)':
../test_server/main.cpp:12: error: undefined reference to `sql::SQLString::SQLString(char const*)'
../test_server/main.cpp:16: undefined reference to `sql::operator<<(std::ostream&, sql::SQLString const&)'
:-1: error: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::~pair()':
/usr/include/c++/11/bits/stl_pair.h:211: error: undefined reference to `sql::SQLString::~SQLString()'
:-1: error: /usr/include/c++/11/bits/stl_pair.h:211: undefined reference to `sql::SQLString::~SQLString()'
:-1: error: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair<char const (&) [5], char const (&) [8], true>(char const (&) [5], char const (&) [8])':
When compiling with g ++ directly from the console, it compiles without problems by passing the libraries as parameters, excluding the library in the main.cpp file.
g++ -o test_server main.cpp -std=c++11 -lmariadbcpp
In the .pro file I have created the link to the mariadb libraries that I have installed without any problem.
test_server.pro.
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += \
main.cpp
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
unix:CONFIG(release, debug|release): LIBS += -L/usr/lib64 -lmariadbcpp
unix {
INCLUDEPATH += /usr/include/mariadb -I..include
DEPENDPATH += /usr/include/mariadb -I..include
}
In the main function the following code: main.cpp
#include <QCoreApplication>
#include <iostream>
#include <mariadb/conncpp.hpp>
void printContacts(std::shared_ptr<sql::Statement> &stmnt)
{
try
{
std::unique_ptr<sql::ResultSet> res(
stmnt->executeQuery("SHOW DATABASES")
);
while (res->next())
{
std::cout << "- "
<< res->getString(1)
<< " " << std::endl;
}
}
catch (sql::SQLException& e)
{
std::cerr << "Error printing contacts: "
<< e.what() << std::endl;
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
try
{
sql::Driver* driver = sql::mariadb::get_driver_instance();
sql::SQLString url("jdbc:mariadb://127.0.0.1:3306/bt");
sql::Properties properties({
{"user", "mysuser"},
{"password", "mypassword"}
});
std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));
std::shared_ptr<sql::Statement> stmnt(conn->createStatement());
printContacts(stmnt);
conn->close();
}
catch (sql::SQLException &e)
{
std::cerr << "Error Connecting to MariaDB Platform: "
<< e.what() << std::endl;
return 1;
}
return a.exec();
}
Build output
22:08:05: Running steps for project test_server...
22:08:05: Configuration unchanged, skipping qmake step.
22:08:05: Starting: "/usr/bin/make" -j4
g++ -c -pipe -g -std=gnu++11 -Wall -Wextra -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_CORE_LIB -I../test_server -I. -I/usr/include/mariadb -I-I..include -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I. -I/../lib64/qt5/mkspecs/linux-g++ -o main.o ../test_server/main.cpp
g++ -o test_server main.o /usr/lib64/libQt5Core.so -lpthread
/usr/bin/ld: main.o: in function `printContacts(std::shared_ptr<sql::Statement>&)':
/home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:12: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:12: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:16: undefined reference to `sql::operator<<(std::ostream&, sql::SQLString const&)'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:16: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:25: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:16: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `main':
/home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:34: undefined reference to `sql::mariadb::get_driver_instance()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:35: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:44: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:44: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::~pair()':
/usr/include/c++/11/bits/stl_pair.h:211: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:211: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair<char const (&) [5], char const (&) [8], true>(char const (&) [5], char const (&) [8])':
/usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair<char const (&) [9], char const (&) [11], true>(char const (&) [9], char const (&) [11])':
/usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::less<sql::SQLString>::operator()(sql::SQLString const&, sql::SQLString const&) const':
/usr/include/c++/11/bits/stl_function.h:386: undefined reference to `sql::SQLString::operator<(sql::SQLString const&) const'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair(std::pair<sql::SQLString const, sql::SQLString> const&)':
/usr/include/c++/11/bits/stl_pair.h:314: undefined reference to `sql::SQLString::SQLString(sql::SQLString const&)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:314: undefined reference to `sql::SQLString::SQLString(sql::SQLString const&)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:314: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o:(.data.rel.local.DW.ref._ZTIN3sql12SQLExceptionE[DW.ref._ZTIN3sql12SQLExceptionE]+0x0): undefined reference to `typeinfo for sql::SQLException'
collect2: error: ld returned 1 exit status
make: *** [Makefile:143: test_server] Error 1
22:08:05: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test_server (kit: Desktop)
When executing step "Make"
22:08:05: Elapsed time: 00:00.
I have downloaded and installed this C++ package for plotting and visulisation https://github.com/alandefreitas/matplotplusplus. I have sussessfully linked to it in my CMake file and have no linking errors when including #include <matplot/matplot.h>. However, whenever I use any functions from the library matplot.h I get the following error at compilation.
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_cimg_jpeg_error_exit(jpeg_common_struct*)':
common.cpp:(.text._ZN12cimg_library4CImgIhE21_cimg_jpeg_error_exitEP18jpeg_common_struct[_ZN12cimg_library4CImgIhE21_cimg_jpeg_error_exitEP18jpeg_common_struct]+0x1e): undefined reference to `jpeg_destroy'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_save_jpeg(_IO_FILE*, char const*, unsigned int) const':
common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x12b): undefined reference to `jpeg_std_error'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x152): undefined reference to `jpeg_CreateCompress'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x16d): undefined reference to `jpeg_stdio_dest'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x198): undefined reference to `jpeg_set_defaults'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x1b2): undefined reference to `jpeg_set_quality'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x1c6): undefined reference to `jpeg_start_compress'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x2cf): undefined reference to `jpeg_write_scanlines'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x2ed): undefined reference to `jpeg_finish_compress'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x302): undefined reference to `jpeg_destroy_compress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_save_png(_IO_FILE*, char const*, unsigned int) const':
common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x2f4): undefined reference to `png_create_write_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x309): undefined reference to `png_create_info_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x32b): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x34f): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x409): undefined reference to `png_init_io'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x474): undefined reference to `png_set_IHDR'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x485): undefined reference to `png_write_info'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0xc36): undefined reference to `png_write_image'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0xc43): undefined reference to `png_write_end'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0xc50): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x1830): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::save_cimg(char const*, bool) const':
common.cpp:(.text._ZNK12cimg_library4CImgIhE9save_cimgEPKcb[_ZNK12cimg_library4CImgIhE9save_cimgEPKcb]+0x3bb): undefined reference to `compress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_load_png(_IO_FILE*, char const*, unsigned int*)':
common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x88): undefined reference to `png_sig_cmp'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xa2): undefined reference to `png_create_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xb7): undefined reference to `png_create_info_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xcd): undefined reference to `png_create_info_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xef): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x14a): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x1c9): undefined reference to `png_init_io'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x1d7): undefined reference to `png_set_sig_bytes'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x1e4): undefined reference to `png_read_info'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x20e): undefined reference to `png_get_IHDR'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x252): undefined reference to `png_get_valid'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x280): undefined reference to `png_set_filler'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x28d): undefined reference to `png_read_update_info'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x2c2): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x369): undefined reference to `png_set_expand_gray_1_2_4_to_8'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x389): undefined reference to `png_set_gray_to_rgb'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x3a9): undefined reference to `png_set_tRNS_to_alpha'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x41f): undefined reference to `png_read_image'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x42c): undefined reference to `png_read_end'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x461): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x4f1): undefined reference to `png_set_palette_to_rgb'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x683): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x84a): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x9d3): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImgList<unsigned char>::_load_cimg(_IO_FILE*, char const*)':
common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x404): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x70c): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x93b): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0xce5): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x10f7): undefined reference to `uncompress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o):common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x1506): more undefined references to `uncompress' follow
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_load_jpeg(_IO_FILE*, char const*)':
common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x67): undefined reference to `jpeg_std_error'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xb3): undefined reference to `jpeg_CreateDecompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xc5): undefined reference to `jpeg_stdio_src'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xd2): undefined reference to `jpeg_read_header'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xda): undefined reference to `jpeg_start_decompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x1f8): undefined reference to `jpeg_read_scanlines'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x278): undefined reference to `jpeg_finish_decompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x284): undefined reference to `jpeg_destroy_decompress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(network.cpp.o): in function `matplot::network::process_force_layout()':
network.cpp:(.text+0x304e): undefined reference to `nodesoup::size_radiuses(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, double, double)'
/usr/bin/ld: network.cpp:(.text+0x312a): undefined reference to `nodesoup::fruchterman_reingold(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, unsigned int, unsigned int, unsigned int, double, std::function<void (std::vector<nodesoup::Point2D, std::allocator<nodesoup::Point2D> > const&, int)>)'
/usr/bin/ld: /usr/local/lib/libmatplot.a(network.cpp.o): in function `matplot::network::process_kawai_layout()':
network.cpp:(.text+0x3842): undefined reference to `nodesoup::size_radiuses(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, double, double)'
/usr/bin/ld: network.cpp:(.text+0x390c): undefined reference to `nodesoup::kamada_kawai(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, unsigned int, unsigned int, double, double)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/example.dir/build.make:84: example] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/example.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
The errors are plenty, but they are all of the form undefined reference to png_... or undefined reference to jpeg_... except for those that are undefined reference to 'uncompress'. It seems as though CMake is not finding png and jpeg. I definitely do have libjpeg and libpng installed. Why are these errors ocurring? Do I need to add lines to my CMakeLists.txt to find jpeg and png? I am running Ubuntu 20.04, g++ 9.3.0, and cmake 3.16.3.
Here is a very simple example that prodces the error. This is the cmake file
cmake_minimum_required(VERSION 3.10)
project(example)
set(CMAKE_CXX_COMPILER "c++")
find_package(Matplot++)
add_executable(example example.cpp)
target_link_libraries(example PUBLIC matplot)
Here is an example c++ code (pulled directly from the examples on the linked site).
#include <cmath>
#include <matplot/matplot.h>
int main() {
using namespace matplot;
std::vector<double> x = linspace(0, 10, 150);
std::vector<double> y = transform(x, [](auto x) { return cos(5 * x); });
plot(x, y)->color({0, 0.7, 0.9});
title("2-D Line Plot");
xlabel("x");
ylabel("cos(5x)");
show();
return 0;
}
I had the same problem (with Windows MinGW). Thanks to #drescherjm hint (add the option -DBUILD_SHARED_LIBS=ON), these are the steps I used to solve the problem:
git clone http://github.com/alandefreitas/matplotplusplus
cd matplotplusplus/
mkdir compil-release && cd compil-release
rm CMakeCache.txt # if already exists
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="${YOUR_LIB_PATH}/matplot1.0.1"
make -j4 && make install
Then, and I guess that is a bug, I had to manually copy the .dll to the install path
cp source/matplot/libmatplot.dll ${YOUR_LIB_PATH}/matplot1.0.1/lib/
Hope this works for you.
I built the latest stable version of allegro5's source code following these steps
I have the following code (main.cpp):
#include <stdint.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
int main()
{
al_init();
al_install_keyboard();
al_install_mouse();
al_init_primitives_addon();
al_set_new_display_flags(ALLEGRO_RESIZABLE);
ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
al_set_window_title(display, "Allegro5 Window");
ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
al_register_event_source(queue, al_get_display_event_source(display));
al_register_event_source(queue, al_get_keyboard_event_source());
al_register_event_source(queue, al_get_mouse_event_source());
bool running = true;
while (running)
{
ALLEGRO_EVENT ev;
while (al_get_next_event(queue, &ev))
{
if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
running = false;
if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
{
al_acknowledge_resize(display);
}
}
al_clear_to_color(al_map_rgba_f(0.25, 0.25, 0.25, 1));
al_flip_display();
}
al_destroy_event_queue(queue);
al_destroy_display(display);
return 0;
}
... And I am trying to build this source file using the following command:
g++ -g $(pkg-config --libs --static allegro-static-5 allegro_primitives-static-5) main.cpp -o main
Even though pkg-config detects everything, it still doesn't work. The output is:
/usr/bin/ld: /tmp/ccmxycjk.o: in function `main':
pwd/main.cpp:7: undefined reference to `al_install_system'
/usr/bin/ld: pwd/main.cpp:8: undefined reference to `al_install_keyboard'
/usr/bin/ld: pwd/main.cpp:9: undefined reference to `al_install_mouse'
/usr/bin/ld: pwd/main.cpp:10: undefined reference to `al_init_primitives_addon'
/usr/bin/ld: pwd/main.cpp:11: undefined reference to `al_set_new_display_flags'
/usr/bin/ld: pwd/main.cpp:12: undefined reference to `al_create_display'
/usr/bin/ld: pwd/main.cpp:13: undefined reference to `al_set_window_title'
/usr/bin/ld: pwd/main.cpp:14: undefined reference to `al_create_event_queue'
/usr/bin/ld: pwd/main.cpp:15: undefined reference to `al_get_display_event_source'
/usr/bin/ld: pwd/main.cpp:15: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:16: undefined reference to `al_get_keyboard_event_source'
/usr/bin/ld: pwd/main.cpp:16: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:17: undefined reference to `al_get_mouse_event_source'
/usr/bin/ld: pwd/main.cpp:17: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:23: undefined reference to `al_get_next_event'
/usr/bin/ld: pwd/main.cpp:29: undefined reference to `al_acknowledge_resize'
/usr/bin/ld: pwd/main.cpp:33: undefined reference to `al_map_rgba_f'
/usr/bin/ld: pwd/main.cpp:33: undefined reference to `al_clear_to_color'
/usr/bin/ld: pwd/main.cpp:34: undefined reference to `al_flip_display'
/usr/bin/ld: pwd/main.cpp:37: undefined reference to `al_destroy_event_queue'
/usr/bin/ld: pwd/main.cpp:38: undefined reference to `al_destroy_display'
OBS: PWD = project path. Running up-to-date Debian 10
I've tried compiling with '-l:', adding all the libs, etc. Nothing would work. Any ideas?
Before you #include <allegro5/...>, add:
#define ALLEGRO_STATICLINK
You may need to link with additional libraries used by Allegro as well, such as OpenGL32.lib (on Windows), to resolve OpenGL functions.
I've just started to learn openGL programming with the openGL Superbible. Unfortunately I'm not able compile any example. I'm on Ubuntu 18.10 and I prepared the development environment with these packages from the official repository:
mesa-common-dev (with these package you get header files in /usr/include/GL/)
libglfw3-dev (header files in /usr/include/GLFW/)
The book uses a small framework with an entry point in the sb7.h header (in the book source code), sb7.h then points to glfw3 and gl3w (the latter given with the book's source code, so you don't need to download it).
This is the first example from the book:
#ifndef _LINUX
#define _LINUX
#endif
// Include the "sb7.h" header file
#include "sb7.h"
// Derive my_application from sb7::application
class my_application : public sb7::application
{
public:
// Our rendering function
void render(double currentTime)
{
// Simply clear the window with red
static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, red);
}
};
// Our one and only instance of DECLARE_MAIN
DECLARE_MAIN(my_application);
If I try to compile it (the file is called 'main.cpp') with g++ main.cpp -lglfw I get this error:
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::run(sb7::application*)':
main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x27e): undefined reference to `gl3wInit'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x29f): undefined reference to `gl3wIsSupported'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2af): undefined reference to `gl3wDebugMessageCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2bd): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2c9): undefined reference to `gl3wEnable'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2de): undefined reference to `sb6IsExtensionSupported(char const*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2ee): undefined reference to `gl3wDebugMessageCallbackARB'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2fc): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x308): undefined reference to `gl3wEnable'
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::glfw_onResize(GLFWwindow*, int, int)':
main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x15): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::glfw_onKey(GLFWwindow*, int, int, int, int)':
main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x23): undefined reference to `sb7::application::app'
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::glfw_onMouseButton(GLFWwindow*, int, int, int)':
main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x18): undefined reference to `sb7::application::app'
/usr/bin/ld: /tmp/ccDOdloQ.o:main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x1f): more undefined references to `sb7::application::app' follow
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `my_application::render(double)':
main.cpp:(.text._ZN14my_application6renderEd[_ZN14my_application6renderEd]+0x14): undefined reference to `gl3wClearBufferfv'
collect2: error: ld returned 1 exit status
Reading the messages I thought that something was wrong with the gl3w library, so I downloaded it from the github repository and I put it and glcorearb.h in /usr/include/GL/, pointing the #include in sb7.h to that folder. Eventually I compiled gl3w.c and linked it to main.cpp with g++ as written here:
g++ -c gl3w.c
g++ -c main.cpp
g++ gl3w.o main.o
but when I execute 3) I get other errors:
/usr/bin/ld: gl3w.o: in function `open_libgl()':
gl3w.c:(.text+0x16): undefined reference to `dlopen'
/usr/bin/ld: gl3w.c:(.text+0x4d): undefined reference to `dlsym'
/usr/bin/ld: gl3w.o: in function `close_libgl()':
gl3w.c:(.text+0x6f): undefined reference to `dlclose'
/usr/bin/ld: gl3w.o: in function `get_proc(char const*)':
gl3w.c:(.text+0xc5): undefined reference to `dlsym'
/usr/bin/ld: main.o: in function `sb7::application::run(sb7::application*)':
main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x21): undefined reference to `glfwInit'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x7c): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x92): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xb3): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xd4): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xe3): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.o:main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xf2): more undefined references to `glfwWindowHint' follow
/usr/bin/ld: main.o: in function `sb7::application::run(sb7::application*)':
main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x13f): undefined reference to `glfwGetPrimaryMonitor'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x172): undefined reference to `glfwCreateWindow'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1c8): undefined reference to `glfwMakeContextCurrent'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1e2): undefined reference to `glfwSetWindowSizeCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1fc): undefined reference to `glfwSetKeyCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x216): undefined reference to `glfwSetMouseButtonCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x230): undefined reference to `glfwSetCursorPosCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x24a): undefined reference to `glfwSetScrollCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x279): undefined reference to `glfwSetInputMode'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2af): undefined reference to `gl3wDebugMessageCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2bd): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2c9): undefined reference to `gl3wEnable'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2de): undefined reference to `sb6IsExtensionSupported(char const*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2ee): undefined reference to `gl3wDebugMessageCallbackARB'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2fc): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x308): undefined reference to `gl3wEnable'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x339): undefined reference to `glfwGetTime'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x355): undefined reference to `glfwSwapBuffers'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x35a): undefined reference to `glfwPollEvents'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x372): undefined reference to `glfwGetKey'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x39b): undefined reference to `glfwWindowShouldClose'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x3e7): undefined reference to `glfwDestroyWindow'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x3ec): undefined reference to `glfwTerminate'
/usr/bin/ld: main.o: in function `sb7::application::glfw_onResize(GLFWwindow*, int, int)':
main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x15): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.o: in function `sb7::application::glfw_onKey(GLFWwindow*, int, int, int, int)':
main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x23): undefined reference to `sb7::application::app'
/usr/bin/ld: main.o: in function `sb7::application::glfw_onMouseButton(GLFWwindow*, int, int, int)':
main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x18): undefined reference to `sb7::application::app'
/usr/bin/ld: main.o:main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x1f): more undefined references to `sb7::application::app' follow
/usr/bin/ld: main.o: in function `my_application::render(double)':
main.cpp:(.text._ZN14my_application6renderEd[_ZN14my_application6renderEd]+0x14): undefined reference to `gl3wClearBufferfv'
collect2: error: ld returned 1 exit status
At this point I tried with the single file version of gl3w.h which already includes gl3w.c. I put the two headers in /usr/include/GL/ and then I pointed sb7.h to that version of the library, but other errors appeared with g++ main.cpp -lglfw:
In file included from main.cpp:6:
sb7.h: In member function ‘virtual void sb7::application::run(sb7::application*)’:
sb7.h:137:9: error: ‘gl3wInit’ was not declared in this scope
gl3wInit();
^~~~~~~~
sb7.h:137:9: note: suggested alternative: ‘glfwInit’
gl3wInit();
^~~~~~~~
glfwInit
sb7.h:147:17: error: ‘gl3wIsSupported’ was not declared in this scope
if (gl3wIsSupported(4, 3))
^~~~~~~~~~~~~~~
sb7.h:147:17: note: suggested alternative: ‘gl3w_is_supported’
if (gl3wIsSupported(4, 3))
^~~~~~~~~~~~~~~
gl3w_is_supported
I also added #define GL3W_IMPLEMENTATION before #include "GL/gl3w.h" as suggested in the documentation of the single file version of gl3w but with no luck.
I get the same errors with the other book's source codes.
Hope that someone can help me.
Thank you.