billyquith / GWork

Skinnable GUI with useful widget collection. Fork of GWEN.
https://billyquith.github.io/GWork/
Other
216 stars 30 forks source link

Code in header files #57

Closed Nopey closed 7 years ago

Nopey commented 7 years ago

I have not done an exhaustive search, but I noticed there is code inside some of the header files. The ones I saw were the 3 headers related to skins, Texturing, TextureBase, and Simple. This isn't inherently a problem, but it causes undefined reference exceptions when I'm linking my program.

eXpl0it3r commented 7 years ago

I think you need to be a bit more specific. Linker errors are in my experience pretty much always a user error, but given the various renderers and platforms, it may well be an oversight.

Nopey commented 7 years ago

It is giving undefined references to the following:

Gwk::Renderer::SFML2::SFML2
Gwk::Controls::Canvas::Canvas
TestFrame::TestFrame
Gwk::Skin::Base::Base
Gwk::Skin::Base::~Base
Gwk::Skin::TexturedBase::DrawTreeNode
Gwk::Skin::Base::DrawPropertyRow
Gwk::Skin::Base::DrawPropertyTreeNode
Gwk::Skin::Base::DrawArrowDown
Gwk::Skin::Base::DrawArrowUp
Gwk::Skin::Base::DrawArrowLeft
Gwk::Skin::Base::DrawArrowRight
Gwk::Skin::Base::DrawCheck

and

vtable for Gwk::Skin::Base
typeinfo for Gwk::Skin::Base

I am linking to libGwork.a, LibGworkTest.a, and LibGworkSFML2.a

billyquith commented 7 years ago

Can you please specify which platform, compiler, and the link errors when you report errors. Versions also useful. Link errors can be caused for different reasons, depending on the platform, and the errors reported.

Currently shared libraries (and BUILD_SHARED_LIBS) are untested and unsupported.

Nopey commented 7 years ago

Not linking with shared libs. Ubuntu 17.04 (zesty)

gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
Linux OptiPlex-GX620 4.10.0-28-generic #32-Ubuntu SMP Fri Jun 30 05:32:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Full Unabridged Linker error:

[ 96%] Linking CXX executable nara
CMakeFiles/nara.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x988): undefined reference to `Gwk::Renderer::SFML2::SFML2(sf::RenderTarget&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
main.cpp:(.text+0xaac): undefined reference to `Gwk::Controls::Canvas::Canvas(Gwk::Skin::Base*)'
main.cpp:(.text+0xbc4): undefined reference to `TestFrame::TestFrame(Gwk::Controls::Base*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
main.cpp:(.text+0x15e5): undefined reference to `Gwk::Renderer::SFML2::~SFML2()'
main.cpp:(.text+0x187e): undefined reference to `Gwk::Renderer::SFML2::~SFML2()'
CMakeFiles/nara.dir/src/main.cpp.o: In function `Gwk::Skin::Base::Base(Gwk::Renderer::Base*)':
main.cpp:(.text._ZN3Gwk4Skin4BaseC2EPNS_8Renderer4BaseE[_ZN3Gwk4Skin4BaseC5EPNS_8Renderer4BaseE]+0x14): undefined reference to `vtable for Gwk::Skin::Base'
CMakeFiles/nara.dir/src/main.cpp.o: In function `Gwk::Skin::Base::~Base()':
main.cpp:(.text._ZN3Gwk4Skin4BaseD2Ev[_ZN3Gwk4Skin4BaseD5Ev]+0xf): undefined reference to `vtable for Gwk::Skin::Base'
CMakeFiles/nara.dir/src/main.cpp.o: In function `Gwk::Skin::TexturedBase::DrawTreeNode(Gwk::Controls::Base*, bool, bool, int, int, int, int, bool)':
main.cpp:(.text._ZN3Gwk4Skin12TexturedBase12DrawTreeNodeEPNS_8Controls4BaseEbbiiiib[_ZN3Gwk4Skin12TexturedBase12DrawTreeNodeEPNS_8Controls4BaseEbbiiiib]+0xd9): undefined reference to `Gwk::Skin::Base::DrawTreeNode(Gwk::Controls::Base*, bool, bool, int, int, int, int, bool)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTVN3Gwk4Skin12TexturedBaseE[_ZTVN3Gwk4Skin12TexturedBaseE]+0x148): undefined reference to `Gwk::Skin::Base::DrawPropertyRow(Gwk::Controls::Base*, int, bool, bool)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTVN3Gwk4Skin12TexturedBaseE[_ZTVN3Gwk4Skin12TexturedBaseE]+0x150): undefined reference to `Gwk::Skin::Base::DrawPropertyTreeNode(Gwk::Controls::Base*, int, int)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTVN3Gwk4Skin12TexturedBaseE[_ZTVN3Gwk4Skin12TexturedBaseE]+0x190): undefined reference to `Gwk::Skin::Base::DrawArrowDown(Gwk::Rect)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTVN3Gwk4Skin12TexturedBaseE[_ZTVN3Gwk4Skin12TexturedBaseE]+0x198): undefined reference to `Gwk::Skin::Base::DrawArrowUp(Gwk::Rect)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTVN3Gwk4Skin12TexturedBaseE[_ZTVN3Gwk4Skin12TexturedBaseE]+0x1a0): undefined reference to `Gwk::Skin::Base::DrawArrowLeft(Gwk::Rect)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTVN3Gwk4Skin12TexturedBaseE[_ZTVN3Gwk4Skin12TexturedBaseE]+0x1a8): undefined reference to `Gwk::Skin::Base::DrawArrowRight(Gwk::Rect)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTVN3Gwk4Skin12TexturedBaseE[_ZTVN3Gwk4Skin12TexturedBaseE]+0x1b0): undefined reference to `Gwk::Skin::Base::DrawCheck(Gwk::Rect)'
CMakeFiles/nara.dir/src/main.cpp.o:(.data.rel.ro._ZTIN3Gwk4Skin12TexturedBaseE[_ZTIN3Gwk4Skin12TexturedBaseE]+0x10): undefined reference to `typeinfo for Gwk::Skin::Base'
collect2: error: ld returned 1 exit status
CMakeFiles/nara.dir/build.make:99: recipe for target 'nara' failed
make[2]: *** [nara] Error 1
CMakeFiles/Makefile2:69: recipe for target 'CMakeFiles/nara.dir/all' failed
make[1]: *** [CMakeFiles/nara.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

https://pastebin.com/QuaQ5Gft

How I'm compiling gwork:

include(ExternalProject)
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/thirdparty)
ExternalProject_Add(
            gwork
      GIT_REPOSITORY "https://github.com/billyquith/GWork.git"
      GIT_TAG "gwork"
            CMAKE_ARGS "-DRENDER_SFML2=ON -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/thirdparty/gwork-install/"
            EXCLUDE_FROM_ALL
)
include_directories(${CMAKE_BINARY_DIR}/thirdparty/gwork-install/include/)
set(OBJECTS ${OBJECTS} ${CMAKE_BINARY_DIR}/thirdparty/gwork-install/lib/libGwork.a ${CMAKE_BINARY_DIR}/thirdparty/gwork-install/lib/libGworkSFML2.a ${CMAKE_BINARY_DIR}/thirdparty/gwork-install/lib/libGworkTest.a)
set(DEPENDANCIES ${DEPENDANCIES} gwork)
Nopey commented 7 years ago

issue is fixed by putting static libs into target_link_libraries instead of passing them in as an object. Code is still in headers, but its not what was causing my linker errors. If you do not mind having code in your headers, this issue can be closed.

billyquith commented 7 years ago

If you do not mind having code in your headers, this issue can be closed.

I don't have any problem with it. Most of it comes from GWEN. It makes the code easier to maintain.

It won't cause a problem if you are static linking, and wasn't what caused your problems. Dynamic linking is currently unsupported and symbols will need to be exported to fix this.