While compiling/linking this code:
#include <string>
using std::string;
#include <pcrecpp.h>
using pcrecpp::RE;
int main() {
string
subj ("Hello world!"),
rgx ("lolCat([0-9])"),
result;
RE(rgx).FullMatch(subj, &result);
}
... by using this command:
i586-mingw32msvc-g++ -std=c++11 -o test.exe -Ipcre-install/include test.cpp \
pcre-install/lib/libpcre.a \
pcre-install/lib/libpcrecpp.a \
pcre-install/lib/libpcreposix.a
... I get this error(s):
/tmp/ccAR72nT.o:test.cpp:(.text+0x119): undefined reference to `_imp___ZN7pcrecpp2RE6no_argE'
/tmp/ccAR72nT.o:test.cpp:(.text+0x123): undefined reference to `_imp___ZN7pcrecpp2RE6no_argE'
/tmp/ccAR72nT.o:test.cpp:(.text+0x12d): undefined reference to `_imp___ZN7pcrecpp2RE6no_argE'
/tmp/ccAR72nT.o:test.cpp:(.text+0x137): undefined reference to `_imp___ZN7pcrecpp2RE6no_argE'
/tmp/ccAR72nT.o:test.cpp:(.text+0x141): undefined reference to `_imp___ZN7pcrecpp2RE6no_argE'
/tmp/ccAR72nT.o:test.cpp:(.text+0x14b): more undefined references to `_imp___ZN7pcrecpp2RE6no_argE' follow
/tmp/ccAR72nT.o:test.cpp:(.text+0x1bd): undefined reference to `_imp___ZNK7pcrecpp2RE9FullMatchERKNS_11StringPieceERKNS_3ArgES6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_'
/tmp/ccAR72nT.o:test.cpp:(.text+0x1d6): undefined reference to `_imp___ZN7pcrecpp2RED1Ev'
/tmp/ccAR72nT.o:test.cpp:(.text+0x294): undefined reference to `_imp___ZN7pcrecpp2RED1Ev'
/tmp/ccAR72nT.o:test.cpp:(.text$_ZN7pcrecpp3ArgC1EPSs[__ZN7pcrecpp3ArgC1EPSs]+0x16): undefined reference to `_imp___ZN7pcrecpp3Arg12parse_stringEPKciPv'
/tmp/ccAR72nT.o:test.cpp:(.text$_ZN7pcrecpp2REC1ERKSs[__ZN7pcrecpp2REC1ERKSs]+0x6a): undefined reference to `_imp___ZN7pcrecpp2RE4InitERKSsPKNS_10RE_OptionsE'
collect2: error: ld returned 1 exit status
Am I doing anything wrong?
libpcrecpp was compiled with this configuration:
../pcre3-8.35/configure --host=i586-mingw32msvc \
--enable-shared=no --enable-static=yes \
--prefix="$(readlink -m ../pcre-install)"
You have compile pcrecpp as static library and you need to define PCRE_STATIC when compiling your code, see https://github.com/vmg/pcre/blob/a257f5c7acc12e64dc2b5aa170b8e4b87dc34f83/pcreposix.h#L117
i586-mingw32msvc-g++ -std=c++11 -o test.exe -DPCRE_STATIC -Ipcre-install/include test.cpp \
pcre-install/lib/libpcre.a \
pcre-install/lib/libpcrecpp.a \
pcre-install/lib/libpcreposix.a
Without PCRE_STATIC all public functions marked as dllimport and have different name mangling
You must define PCRE_STATIC (i.e. -DPCRE_STATIC).
Related
I'm trying google mock testing using Qt Creator in Windows, but it turns to have so many different undefined reference errors.
I tried it in Linux and it's working. I don't know if I have a wrong setup with gmock when it comes to Windows.
Here's the code with issues on MOCK_CONST_METHOD2, MOCK_METHOD2, MOCK_METHOD1, and on the first two EXPECT_CALL. And also have issues on gmock header files.
main.cpp
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mail_service.hpp"
#include "warehouse.hpp"
#include "order.hpp"
using ::testing::Return;
using ::testing::_; // Matcher for parameters
/** \brief Mock for the warehouse interface.
* \author David Stutz
*/
class MockWarehouse : public Warehouse
{
public:
// see https://github.com/google/googletest/blob/master/googlemock/docs/ForDummies.md
MOCK_CONST_METHOD2(hasInventory, bool(int, std::string));
MOCK_METHOD2(remove, void(int, std::string));
};
/** \brief Mock for the mail service interface.
* \author David Stutz
*/
class MockMailService : public MailService
{
public:
MockMailService()
{
}
MOCK_METHOD1(send, void(std::string));
};
TEST(OrderTest, Fill)
{
MockWarehouse warehouse;
std::shared_ptr<MockMailService> mailService = std::make_shared<MockMailService>();
Order order(50, "Talisker");
order.setMailService(mailService);
EXPECT_CALL(warehouse, hasInventory(50, "Talisker"))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(warehouse, remove(50, "Talisker"))
.Times(1);
EXPECT_CALL(*mailService, send(_)) // Not making assumptions on the message send ...
.Times(1);
ASSERT_TRUE(order.fill(warehouse));
}
/** \brief Main test entrance point.
* \param[in] argc
* \param[in] argv
*/
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
headers
mail_service.hpp
#ifndef MAIL_SERVICE_HPP
#define MAIL_SERVICE_HPP
class MailService
{
public:
/** \brief Send a mial.
* \param[in] message message to send
*/
virtual void send(std::string message) = 0;
};
#endif /* MAIL_SERVICE_HPP */
order.hpp
#ifndef ORDER_HPP
#define ORDER_HPP
#include <string>
#include <memory>
#include "warehouse.hpp"
#include "mail_service.hpp"
/** \brief An order of a product with quantity. */
class Order
{
public:
/** \brief Constructor.
* \param[in] quantity quantity requested
* \param[in] product product name requested
*/
Order(int quantity, std::string product)
{
this->quantity = quantity;
this->product = product;
}
/** \brief Set the mail service to use.
* \param[in] mailService the mail service to attach
*/
void setMailService(std::shared_ptr<MailService> mailService)
{
this->mailService = mailService;
}
/** \brief Fill the order given the warehouse.
* \param[in] warehouse the warehouse to use
* \return whether the operation was successful
*/
bool fill(Warehouse &warehouse)
{
if (warehouse.hasInventory(quantity, product))
{
// ...
warehouse.remove(quantity, product);
this->mailService->send("Order filled.");
return true;
}
else
{
// ...
this->mailService->send("Order not filled.");
return false;
}
}
private:
/** \brief Product name. */
std::string product;
/** \brief Quantity requested. */
int quantity;
/** \brief Mail service to use. */
std::shared_ptr<MailService> mailService;
};
#endif /* ORDER_HPP */
warehouse.hpp
#ifndef WAREHOUSE_HPP
#define WAREHOUSE_HPP
#include <string>
/** \brief Warehouse interface. This interface is one of the collaborators of our SUT.
class Warehouse
{
public:
/** \brief Check whether the product in the given quantity is on stock.
* \param[in] quantity quantity requested
* \param[in] product product name
* \return whether the warehouse has the product on stock for the given quantity
*/
virtual bool hasInventory(int quantity, std::string product) const = 0;
/** \brief Remove the given quantity of the product from the warehouse.
* \param[in] quantity quantity to remove
* \param[in] product product name to remove
*/
virtual void remove(int quantity, std::string product) = 0;
};
#endif /* WAREHOUSE_HPP */
Here's the makefile
Here's the .pro file
CONFIG += console c++14
INCLUDEPATH += "google/gmock/include/"
INCLUDEPATH += "google/gmock/"
INCLUDEPATH += "google/gtest/include/"
INCLUDEPATH += "google/gtest/src/"
INCLUDEPATH += "google/gtest/"
INCLUDEPATH += "google/"
INCLUDEPATH += "../../"
SOURCES += \
order.cpp \
google/gtest/src/gtest.cc \
google/gtest/src/gtest-all.cc \
google/gtest/src/gtest-death-test.cc \
google/gtest/src/gtest-filepath.cc \
google/gtest/src/gtest-port.cc \
google/gtest/src/gtest-printers.cc \
google/gtest/src/gtest-test-part.cc \
google/gtest/src/gtest-typed-test.cc
HEADERS += \
mail_service.hpp \
order.hpp \
warehouse.hpp
And here's the compile output errors:
10:53:25: Running steps for project GoogleMockTest2...
10:53:25: Configuration unchanged, skipping qmake step.
10:53:27: Starting: "C:\Qt\Qt5.9.3\Tools\mingw530_32\bin\mingw32-make.exe"
C:\Qt\Qt5.9.3\5.9.3\mingw53_32\bin\qmake.exe -o Makefile ..\GoogleMockTest2\GoogleMockTest2.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
C:/Qt/Qt5.9.3/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/PB9N0052/Documents/build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++1y -Wextra -Wall -W -fexceptions -mthreads -DUNICODE -D_UNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I..\GoogleMockTest2 -I. -I..\GoogleMockTest2\google\googlemock\include -I..\GoogleMockTest2\google\googlemock -I..\GoogleMockTest2\google\googletest\include -I..\GoogleMockTest2\google\googletest\src -I..\GoogleMockTest2\google\googletest -I..\GoogleMockTest2\google -I..\..\..\PB9N0052 -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtGui -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtCore -Idebug -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\mkspecs\win32-g++ -o debug\warehouse.o ..\GoogleMockTest2\warehouse.cpp
g++ -c -fno-keep-inline-dllexport -g -std=gnu++1y -Wextra -Wall -W -fexceptions -mthreads -DUNICODE -D_UNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I..\GoogleMockTest2 -I. -I..\GoogleMockTest2\google\googlemock\include -I..\GoogleMockTest2\google\googlemock -I..\GoogleMockTest2\google\googletest\include -I..\GoogleMockTest2\google\googletest\src -I..\GoogleMockTest2\google\googletest -I..\GoogleMockTest2\google -I..\..\..\PB9N0052 -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtGui -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtCore -Idebug -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\mkspecs\win32-g++ -o debug\mail_service.o ..\GoogleMockTest2\mail_service.cpp
g++ -Wl,-subsystem,console -mthreads -o debug\GoogleMockTest2.exe debug/order.o debug/gtest-all.o debug/warehouse.o debug/mail_service.o -LC:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib C:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\libQt5Guid.a C:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\libQt5Cored.a
debug/order.o: In function `ZN19OrderTest_Fill_Test8TestBodyEv':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/order.cpp:44: undefined reference to `testing::Matcher<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Matcher(char const*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED1Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedFunctionMockerBase()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED1Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedFunctionMockerBase()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED1Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal8MockSpecIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE18InternalExpectedAtEPKciSB_SB_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1271: undefined reference to `testing::internal::LogWithLocation(testing::internal::LogSeverity, char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesEi':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:932: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE8WillOnceERKNS_6ActionIS8_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1002: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal8MockSpecIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE18InternalExpectedAtEPKciSB_SB_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1271: undefined reference to `testing::internal::LogWithLocation(testing::internal::LogSeverity, char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesEi':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:932: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal8MockSpecIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE18InternalExpectedAtEPKciSB_SB_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1271: undefined reference to `testing::internal::LogWithLocation(testing::internal::LogSeverity, char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesEi':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:932: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE10InvokeWithERKSt5tupleIJiS7_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1529: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE10InvokeWithERKSt5tupleIJiS7_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1529: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE25ClearDefaultActionsLockedEv':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::~Expectation()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1551: undefined reference to `testing::internal::UntypedFunctionMockerBase::MockObject() const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1551: undefined reference to `testing::Mock::RegisterUseByOnCallOrExpectCall(void const*, char const*, int)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1558: undefined reference to `testing::internal::g_gmock_implicit_sequence'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::Expectation(testing::internal::linked_ptr<testing::internal::ExpectationBase> const&)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Sequence::AddExpectation(testing::Expectation const&) const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::~Expectation()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::~Expectation()'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesERKNS_11CardinalityE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:926: undefined reference to `testing::internal::ExpectationBase::UntypedTimes(testing::Cardinality const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC1EPNS0_18FunctionMockerBaseIS8_EEPKciRKS7_RKSt5tupleIJNS_7MatcherIiEENSI_IS7_EEEE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:894: undefined reference to `testing::internal::ExpectationBase::ExpectationBase(char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:894: undefined reference to `testing::internal::ExpectationBase::~ExpectationBase()'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC1EPNS0_18FunctionMockerBaseIS8_EEPKciRKS7_RKSt5tupleIJNS_7MatcherIiEENSI_IS7_EEEE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:899: undefined reference to `testing::internal::ExpectationBase::CheckActionCountIfNotDone() const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:904: undefined reference to `testing::internal::ExpectationBase::~ExpectationBase()'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE9GetHandleEv':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1077: undefined reference to `testing::internal::UntypedFunctionMockerBase::GetHandleOf(testing::internal::ExpectationBase*)'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE32UntypedDescribeUninterestingCallEPKvPSo':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1603: undefined reference to `testing::internal::UntypedFunctionMockerBase::Name() const'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE30UntypedFindMatchingExpectationEPKvPSB_PbPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1630: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE32UntypedDescribeUninterestingCallEPKvPSo':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1603: undefined reference to `testing::internal::UntypedFunctionMockerBase::Name() const'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE30UntypedFindMatchingExpectationEPKvPSB_PbPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1630: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE32UntypedDescribeUninterestingCallEPKvPSo':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1603: undefined reference to `testing::internal::UntypedFunctionMockerBase::Name() const'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE30UntypedFindMatchingExpectationEPKvPSB_PbPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1630: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE29FindMatchingExpectationLockedERKSt5tupleIJS7_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1661: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE33FormatUnexpectedCallMessageLockedERKSt5tupleIJS7_EEPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1110: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1128: undefined reference to `testing::internal::ExpectationBase::AllPrerequisitesAreSatisfied() const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1133: undefined reference to `testing::internal::ExpectationBase::FindUnsatisfiedPrerequisites(testing::ExpectationSet*) const'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [debug\GoogleMockTest2.exe] Error 1
mingw32-make: *** [debug] Error 2
Makefile.Debug:74: recipe for target 'debug\GoogleMockTest2.exe' failed
mingw32-make[1]: Leaving directory 'C:/Users/PB9N0052/Documents/build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug'
Makefile:36: recipe for target 'debug' failed
10:53:32: The process "C:\Qt\Qt5.9.3\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project GoogleMockTest2 (kit: Desktop Qt 5.9.3 MinGW 32bit)
When executing step "Make"
10:53:32: Elapsed time: 00:07.
Maybe you forgot to add in your sources the ".cc" files of gmock.
Because in your .pro file, you only added the ".cc" files of gtest.
What I always do is, "add existing files" then look for the src folder of the gmock.
And add the .cc files.
Like this sample:
SOURCES += \
../calculator.cpp \
../button.cpp \
main.cpp \
gtest/src/gtest.cc \
gtest/src/gtest-all.cc \
gtest/src/gtest-death-test.cc \
gtest/src/gtest-filepath.cc \
gtest/src/gtest-port.cc \
gtest/src/gtest-printers.cc \
gtest/src/gtest-test-part.cc \
gtest/src/gtest-typed-test.cc \
gmock/src/gmock-spec-builders.cc \
gmock/src/gmock-matchers.cc \
gmock/src/gmock-internal-utils.cc \
gmock/src/gmock-cardinalities.cc \
gmock/src/gmock-all.cc \
gmock/src/gmock.cc
My new .pro file
CONFIG += console c++14
INCLUDEPATH += "google/googlemock/include/"
INCLUDEPATH += "google/googlemock/"
INCLUDEPATH += "google/googletest/include/"
INCLUDEPATH += "google/googletest/src/"
INCLUDEPATH += "google/googletest/"
INCLUDEPATH += "google/"
INCLUDEPATH += "../../"
SOURCES += \
order.cpp \
google/googletest/src/gtest.cc \
google/googletest/src/gtest-all.cc \
google/googletest/src/gtest-death-test.cc \
google/googletest/src/gtest-filepath.cc \
google/googletest/src/gtest-port.cc \
google/googletest/src/gtest-printers.cc \
google/googletest/src/gtest-test-part.cc \
google/googletest/src/gtest-typed-test.cc \
google/googlemock/src/gmock.cc \
google/googlemock/src/gmock-all.cc \
google/googlemock/src/gmock-cardinalities.cc \
google/googlemock/src/gmock-internal-utils.cc \
google/googlemock/src/gmock-matchers.cc \
google/googlemock/src/gmock-spec-builders.cc
HEADERS += \
mail_service.hpp \
order.hpp \
warehouse.hpp
I had the same issue and the pointer to include the source files for gmock and gtest is the correct lead, but I still got errors on linkage (i'm using CMake).
The error was for multiple definition of functions. The issue was that gtest-all.cc includes all the relevant sources for gtest (and gmock-all.cc does the same for gmock sources). So all you need to do is include gtest-all.cc and gmock-all.cc:
SOURCES += \
../calculator.cpp \
../button.cpp \
main.cpp \
gtest/src/gtest-all.cc \
gmock/src/gmock-all.cc
This is also much cleaner.
I hope this is a good complimentary solution for the answer above, as it solves the next issue in line (at least for me).
Trying to use Boost Python, but getting linkage issues.
Code, hello.cpp:
#include <boost/python.hpp>
char const* greet() {
return "hellow, world";
}
int main() {
return 0;
}
BOOST_PYTHON_MODULE(hello_ext) {
using namespace boost::python;
def("greet", greet);
}
Compiling with:
g++ hello.cpp -L/usr/lib/x86_64-linux-gnu/ -I/usr/include/python3.5/ -lboost_python /usr/lib/x86_64-linux-gnu/libpython3.5m.so -lboost_system
Getting the following linkage errors:
tmp/ccJ8ST4B.o: In function `PyInit_hello_ext':
hello.cpp:(.text+0x94): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_Size'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyUnicodeUCS4_FromEncodedObject'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyFile_FromString'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_Type'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyInt_Type'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromString'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyUnicodeUCS4_AsWideChar'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromStringAndSize'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `Py_InitModule4_64'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromFormat'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyNumber_Divide'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyNumber_InPlaceDivide'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyInt_AsLong'
Any ideas?
Here while compiling give proper, exact and ordered path for libraries. Please use below command and try, If it doesn't work set LD_LIBRARY_PATH(set in program dir path only) to program directory path. This will link all the required library to your program directory.
g++ -I/usr/include/python3.5/ /usr/lib/x86_64-linux-gnu/libpython3.5m.so -L/usr/lib/x86_64-linux-gnu/ -lboost_python -lboost_system hello.cpp -o hello
If above line do not work
export LD_LIBRARY_PATH=/program_path:$LD_LIBRARY_PATH
I am trying to get OGDF working to see if it is suitable for my project, but I am having trouble with a sample program.
I am trying to compile this example program:
#include <ogdf/basic/Graph.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
using namespace ogdf;
int main()
{
Graph G;
randomSimpleGraph(G, 10, 20);
DfsAcyclicSubgraph DAS;
DAS.callAndReverse(G);
G.writeGML("test.gml");
return 0;
}
using this command:
$g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ -lOGDF test2.cpp
But I get the following error
/tmp/ccbpkfdt.o: In function `main':
test2.cpp:(.text+0x12): undefined reference to `ogdf::Graph::Graph()'
test2.cpp:(.text+0x2e): undefined reference to `ogdf::randomSimpleGraph(ogdf::Graph&, int, int)'
test2.cpp:(.text+0x4e): undefined reference to `ogdf::AcyclicSubgraphModule::callAndReverse(ogdf::Graph&)'
test2.cpp:(.text+0x62): undefined reference to `ogdf::Graph::writeGML(char const*) const'
test2.cpp:(.text+0x7f): undefined reference to `ogdf::Graph::~Graph()'
test2.cpp:(.text+0xa1): undefined reference to `ogdf::Graph::~Graph()'
/tmp/ccbpkfdt.o: In function `__static_initialization_and_destruction_0(int, int)':
test2.cpp:(.text+0xfb): undefined reference to `ogdf::Initialization::Initialization()'
test2.cpp:(.text+0x112): undefined reference to `ogdf::Initialization::~Initialization()'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphC2Ev[_ZN4ogdf18DfsAcyclicSubgraphC5Ev]+0x16): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::~DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphD2Ev[_ZN4ogdf18DfsAcyclicSubgraphD5Ev]+0xb): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
collect2: error: ld returned 1 exit status
I tried compiling hello world, with an include from OGDF, and I still got:
undefined reference to `ogdf::Initialization::Initialization()'
I think I am not linking properly or something?
You have to be very careful in which order you type stuff when linking with a library.
Try putting test2.cpp before -lOGDF instead, like this:
g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ test2.cpp -lOGDF
You must build your program using the -DOGDF_DLL when using OGDF as a shared library.
See here: http://www.ogdf.net/doku.php/tech:defines
I've been playing around with clang/llvm 3.0, following the tutorial here
http://amnoid.de/tmp/clangtut/tut.html
The code in the tutorial is a bit outdated but after some modification, it compiles ok (both with clang++/g++, on Ubuntu):
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/Host.h>
#include <llvm/ADT/IntrusiveRefCntPtr.h>
#include <clang/Frontend/DiagnosticOptions.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Basic/TargetOptions.h>
#include <clang/Basic/TargetInfo.h>
#include <clang/Basic/FileManager.h>
#include <clang/Lex/Preprocessor.h>
#include <clang/Lex/HeaderSearch.h>
using namespace clang;
int main()
{
DiagnosticOptions diagOpt;
TextDiagnosticPrinter *pTextDiagPrinter = new TextDiagnosticPrinter(llvm::outs(), diagOpt);
llvm::IntrusiveRefCntPtr<DiagnosticIDs> pDiagIds(new DiagnosticIDs);
DiagnosticsEngine *pDiagEng = new DiagnosticsEngine(pDiagIds, pTextDiagPrinter);
Diagnostic diag(pDiagEng);
LangOptions lang;
FileSystemOptions fmOpt;
FileManager fm(fmOpt);
SourceManager sm(*pDiagEng, fm);
HeaderSearch headers(fm);
TargetOptions tgtOpt;
tgtOpt.Triple = llvm::sys::getHostTriple();
TargetInfo *ti = TargetInfo::CreateTargetInfo(*pDiagEng, tgtOpt);
CompilerInstance comp;
Preprocessor pp(*pDiagEng, lang, ti, sm, headers, comp);
return 0;
}
The problem is linking, I guess the problem is library order, tried various combinations, some gives thousands of undefined symbols, the best I get is with this:
g++ -fno-exceptions -fno-rtti -fno-common \
-lclangParse -lclangSerialization -lclangDriver -lclangSema -lclangAnalysis -lclangAST -lclangFrontend \
-lclangLex -lclangBasic -lclang \
`llvm-config --cxxflags --ldflags --libs` -ldl tut1.cpp
which gives
tut1.cpp:(.text.startup+0xca): undefined reference to `llvm::outs()'
tut1.cpp:(.text.startup+0xef): undefined reference to `clang::TextDiagnosticPrinter::TextDiagnostic
Printer(llvm::raw_ostream&, clang::DiagnosticOptions const&, bool)'
tut1.cpp:(.text.startup+0x104): undefined reference to `clang::DiagnosticIDs::DiagnosticIDs()'
tut1.cpp:(.text.startup+0x13d): undefined reference to `clang::DiagnosticsEngine::DiagnosticsEngine
(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> const&, clang::DiagnosticConsumer*, bool)'
tut1.cpp:(.text.startup+0x14a): undefined reference to `clang::LangOptions::LangOptions()'
tut1.cpp:(.text.startup+0x167): undefined reference to `clang::FileManager::FileManager(clang::File
SystemOptions const&)'
tut1.cpp:(.text.startup+0x17f): undefined reference to `clang::SourceManager::SourceManager(clang::
DiagnosticsEngine&, clang::FileManager&)'
tut1.cpp:(.text.startup+0x194): undefined reference to `clang::HeaderSearch::HeaderSearch(clang::Fi
leManager&)'
tut1.cpp:(.text.startup+0x1f5): undefined reference to `llvm::sys::getHostTriple()'
tut1.cpp:(.text.startup+0x227): undefined reference to `clang::TargetInfo::CreateTargetInfo(clang::
DiagnosticsEngine&, clang::TargetOptions&)'
tut1.cpp:(.text.startup+0x232): undefined reference to `clang::CompilerInstance::CompilerInstance()
'
tut1.cpp:(.text.startup+0x277): undefined reference to `clang::Preprocessor::Preprocessor(clang::Di
agnosticsEngine&, clang::LangOptions&, clang::TargetInfo const*, clang::SourceManager&, clang::Head
erSearch&, clang::ModuleLoader&, clang::IdentifierInfoLookup*, bool, bool)'
tut1.cpp:(.text.startup+0x281): undefined reference to `clang::Preprocessor::~Preprocessor()'
tut1.cpp:(.text.startup+0x289): undefined reference to `clang::CompilerInstance::~CompilerInstance(
)'
tut1.cpp:(.text.startup+0x2e4): undefined reference to `clang::HeaderSearch::~HeaderSearch()'
tut1.cpp:(.text.startup+0x2f1): undefined reference to `clang::SourceManager::~SourceManager()'
tut1.cpp:(.text.startup+0x2fe): undefined reference to `clang::FileManager::~FileManager()'
tut1.cpp:(.text.startup+0x345): undefined reference to `clang::DiagnosticIDs::~DiagnosticIDs()'
collect2: ld returned 1 exit status
I also followed this link Linking against clang-llvm
but seems it doesn't apply to clang 3.0.
Anybody knows how to successfully build the code, or better yet, some tool like some clang-config?
just use the LLVM flags AFTER the .o file, object file won't be linked unless
the flags are written after it. A simple makefile to show what I mean
CC=clang++
LFLAGS=`llvm-config --cppflags --ldflags --libs core`
all:
$(CC) -o out in.cc $(FLAGS)
clang driver itself links with:
-lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangIndex -lclangARCMigrate -lclangRewrite -lclangAST -lclangLex -lclangBasic
A little trick how to find it out: build clang, remove the clang binary, and run make -n.
Some linkers a sensitive to the order of -l* flags when working with static libraries. The of clang libraries seems OK, so try swapping `llvm-config --cxxflags --ldflags --libs` with clang libraries list.
If that don't help, only solution for you is what #SK-logic suggested - run make -n and look at compile command for clang target.
I am a leda-6.3 library user.
I used graphwin to manipulate and display graphs, but I found that references
to graphwin methods are undefined while compiling the code although they
are declared in the LEDA/incl/LEDA/graphics/graphwin.h
So I think it is a problem of object file.
#include <LEDA/graphics/graphwin.h>
#include <LEDA/graph/graph_alg.h>
using namespace leda;
int main()
{
GraphWin gw("LEDA Graph Editor");
node u=gw.new_node(point(100,100));
node v=gw.new_node(point(100,200));
gw.new_edge(u,v);
gw.display();
gw.get_window().read_mouse();
graph& G=gw.get_graph();
G.new_node();
gw.get_window().read_mouse();
gw.update_graph();
gw.get_window().read_mouse();
return 0;
}
compilation: g++ -I$LEDAROOT/incl -L$LEDAROOT gw.cpp -lleda -lX11 -lm -o gw
ERROR :
/tmp/ccVHyRbL.o: In function `main':
gw.cpp:(.text+0x1e): undefined reference to `leda::GraphWin::GraphWin(char const*)'
gw.cpp:(.text+0x58): undefined reference to `leda::GraphWin::new_node(leda::point const&)'
gw.cpp:(.text+0xc6): undefined reference to `leda::GraphWin::new_node(leda::point const&)'
gw.cpp:(.text+0x11c): undefined reference to `leda::GraphWin::new_edge(leda::node_struct*, leda::node_struct*)'
gw.cpp:(.text+0x128): undefined reference to `leda::GraphWin::display()'
gw.cpp:(.text+0x17e): undefined reference to `leda::GraphWin::update_graph()'
collect2: ld returned 1 exit status
Which edition of LEDA are you using?
Please consider that free edition of LEDA does not contain GraphWin.
So, it dos not contain GraphWin libraries, which results to getting such errors while compiling your program.