Note that there are some explanatory texts on larger screens.

plurals
  1. POLTO and virtual destructor weirdness c++
    primarykey
    data
    text
    <p>I'm having issues when compiling/Linking with LTO enabled with GCC 4.8.1. I get undefined references to symbols in a DLL even though they seem to be present. The strange thing is, without LTO enabled it compiles and links successfully. LTO seems to struggle when there is a virtual destructor that hasn't been defined in the derived class. </p> <ul> <li>Removing the DECLSPEC makes it compile and work with LTO enabled. </li> <li>Dependency walker shows the symbols are there. The link time optimizer just can't seem to find them. </li> <li>Declaring any type of destructor in derived class <code>Test</code> makes it work. </li> <li>Removing LTO optimization also makes it work successfully, I'm wondering why this is an issue.</li> </ul> <p>Test is a shared library, Main links to the shared library.</p> <p>Test.h</p> <pre><code>#include &lt;string&gt; #ifdef SOURCE #define DECL __declspec(dllexport) #warning Exporting! #else #define DECL __declspec(dllimport) #warning Importing! #endif class DECL TestBase { public: TestBase(const std::string testing); virtual ~TestBase(); std::string getTesting(); private: std::string _testing; }; class DECL Test : public TestBase { public: Test(const std::string testing); //~Test(); //removing causes a linker error with LTO! Fine without LTO. }; </code></pre> <p>Test.cpp</p> <pre><code>#include "Test.h" TestBase::TestBase(const std::string testing) { _testing = testing; } TestBase::~TestBase() { } std::string TestBase::getTesting() { return _testing; } Test::Test(const std::string testing) : TestBase(testing) { } /*Test::~Test() //removing causes a linker error with LTO! Fine without LTO. { }*/ </code></pre> <p>Main.cpp</p> <pre><code>#include "Test.h" #include &lt;iostream&gt; int main() { Test test("testing!"); std::cout &lt;&lt; test.getTesting() &lt;&lt; std::endl; return 0; } </code></pre> <p>Excuse my messy makefile..</p> <pre><code>CC=g++ LD=g++ LIBCFLAGS= -O3 -march=pentium4 -mfpmath=sse -flto -fuse-linker-plugin LIBEXTRA= -c -DSOURCE LIBLDFLAGS= ${LIBCFLAGS} -shared LIBSOURCES=Test.cpp LIBRARY=Test.dll EXECFLAGS= -O3 -march=pentium4 -mfpmath=sse -flto -fuse-linker-plugin EXTRA= -c EXELDFLAGS= ${EXECFLAGS} -L. -lTest SOURCES=Main.cpp EXECUTABLE=main LIBOBJECTS=$(LIBSOURCES:.cpp=.o) OBJECTS=$(SOURCES:.cpp=.o) all: $(SOURCES) $(LIBRARY) $(EXECUTABLE) $(LIBRARY): $(LIBOBJECTS) $(LD) $(LIBLDFLAGS) $(LIBOBJECTS) -o $@ $(EXECUTABLE): $(OBJECTS) $(LD) $(EXELDFLAGS) $(OBJECTS) -o $@ $(OBJECTS): CFLAGS := $(EXECFLAGS) $(EXTRA) $(LIBOBJECTS): CFLAGS := $(LIBCFLAGS) $(LIBEXTRA) .cpp.o: @echo "... Making: $@" $(CC) $(CFLAGS) $&lt; -o $@ clean: - del /f /q *.o - del /f /q *.dll - del /f /q *.exe </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload