widberg / bgfx.cmake

https://github.com/bkaradzic/bgfx.cmake. Independently maintained CMake build scripts for bgfx. Released under public domain.
https://github.com/bkaradzic/bgfx.cmake
Creative Commons Zero v1.0 Universal
286 stars 254 forks source link

Problem with setting up the project - undefined reference to symbol 'XFree' #11

Closed soraphis closed 7 years ago

soraphis commented 7 years ago

Hi,

i'm kinda sorry to open this as issue, because i think the fault lies by with me - not in this project. But i could not think of another place where i could find help to this

i'm using ubuntu 17.04, and CLion as my IDE.

i created a new C++ Project. it contains my main.cpp, a CMakeLists.txt and a subfolder thirdparty.

i clone the bgfx.cmake repository into the thirdparty subfolder and changed my CMakeLists.txt to look like this:

cmake_minimum_required(VERSION 3.7)
set(CMAKE_CXX_STANDARD 14)
project(bgfx_test)

set(SOURCE_FILES main.cpp)

add_subdirectory("thirdparty/bgfx.cmake")
add_executable(bgfx_test ${SOURCE_FILES} )

target_link_libraries(bgfx_test bx)
target_link_libraries(bgfx_test bgfx)
target_link_libraries(bgfx_test bimg)

#target_include_directories(bgfx_test PUBLIC "cmake-build-debug/thirdparty/bgfx.cmake")

Then i changed my main.cpp to look like the HelloWorld example but with an empty update loop:

#include <bx/uint32_t.h>
#include <bgfx/bgfx.h>
#include "thirdparty/bgfx.cmake/bgfx/examples/common/common.h"
#include "thirdparty/bgfx.cmake/bgfx/examples/common/bgfx_utils.h"

class ExampleHelloWorld : public entry::AppI {
    int shutdown() BX_OVERRIDE {
        return 0;
    }

    bool update() BX_OVERRIDE {
        return false;
    }

    uint32_t m_width;
    uint32_t m_height;
    uint32_t m_debug;
    uint32_t m_reset;

    void init(int _argc, char** _argv) BX_OVERRIDE
    {
        Args args(_argc, _argv);

        m_width  = 1280;
        m_height = 720;
        m_debug  = BGFX_DEBUG_TEXT;
        m_reset  = BGFX_RESET_VSYNC;

        bgfx::init(args.m_type, args.m_pciId);
        bgfx::reset(m_width, m_height, m_reset);

        // Enable debug text.
        bgfx::setDebug(m_debug);

        // Set view 0 clear state.
        bgfx::setViewClear(0
                , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
                , 0x303030ff
                , 1.0f
                , 0
        );
    }
};

ENTRY_IMPLEMENT_MAIN(ExampleHelloWorld);

when i try to run the project i get this error:

/usr/bin/ld: thirdparty/bgfx.cmake/libbgfxd.a(glcontext_glx.cpp.o): undefined reference to symbol 'XFree'

//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status

as i wrote: i'm pretty sure i did something wrong, but i rly can't figure out what. So maybe someone can push me into the right direction.

JoshuaBrookover commented 7 years ago

Hey, no worries about the issue. I should probably setup some simple examples repos using bgfx.cmake.

I've got an easy solution and a hard solution. For the easy solution, you also need to link against example-common. You can shorten your link libraries to just:

target_link_libraries(bgfx_test bgfx example-common)

After that there is no need to include files explicitly like you have. You can simply:

#include "common.h"
#include "bgfx_utils.h"

With these changes you should be up and running.

The hard solution is to not use example-common at all. It's not guaranteed to be production friendly. If you're just using it to learn, then there's no problem. My recommendation is to use GLFW, as I've had the least issues with it, but that's up to you. I have some code you may be able to pull from here if you want to go down that route: https://github.com/JoshuaBrookover/bigg

Best of luck!

soraphis commented 7 years ago

thanks! thanks a lot! that worked just nice. the simple solution is just fine for me, cause i just need it to visualize some project of mine.

onqtam commented 7 years ago

I think you should link to bigg in bgfx.cmake - its a simpler example than the ones coming with bgfx.

Anyway this issue seems ready for closing :)

JoshuaBrookover commented 7 years ago

I'm not totally happy with bigg just yet. That's why I haven't linked it in the readme. It was a weekend project that could probably be done better.

I would like to spend some time writing up some proper examples that aren't so messy. Maybe I can add it for now just so people have some sort of reference.