3

So, I've got a c++ project where i want to visualize stuff (in realtime), so i was looking for a rendering engine, and found bgfx.

I don't write often c++ stuff, and using thirdparty projects seems unbelievable laborious, but maybe i just do everything wrong and hopefully you can push me into the right direction.



My first try was on linux, i cloned bgfx.cmake and followed the readme, then i used make install which installed the librarys to "/usr/local/include".

this seemed to work at first, because my IDE (CLion) recognized bgfx when using #import.

Then i tried to make the HelloWorld example work. i ended up with copying the bgfx examples folder into my project under a subfolder "thirdparty", because all the examples make highly use of the "examples/common" folder.

and i think i made something wrong with my CMakeLists.txt because while my IDE can resolve and autocomplete everything i get a compiler error when I try to run the project:

Unresolved references 'entry::runApp(entry::AppI*, int, char**)'

on the line ENTRY_IMPLEMENT_MAIN(ExampleClass) where ENTRY_IMPLEMENT_MAIN is a bgfx defined macro (here).


after a few annoying hours i decided to start from scratch:

i made a project "bgfx_test" with subfolder "thirdparty" in the thirdparty folder i cloned the bgfx.cmake project, and added add_subdirectory("thirdparty/bgfx.cmake") into my CMakeLists.txt

i again made a main.cpp where i added the ExampleHelloWorld class from the bgfx examples.

i changed it to have a empty update() method, so i did not need the logo.h and screeshot.png file from the example. and i changed the includes to:

#include "thirdparty/bgfx.cmake/bgfx/examples/common/common.h"
#include "thirdparty/bgfx.cmake/bgfx/examples/common/bgfx_utils.h"

the same error again, my IDE autocompletes everything but the compiler says:

Nicht definierter Verweis auf 'entry::runApp(entry::AppI*, int, char**)' (unresolved reference)

if someone could help me with this, that would be awesome

my folder structure:

project-root
    main.cpp
    CMakeLists.txt
    thirdparty
        bgfx.cmake (clone of the repo mentioned above)

my CMakeLists.txt:

cmake_minimum_required(VERSION 3.7)
project(bgfx_test)

set(CMAKE_CXX_STANDARD 14)

set(SOURCE_FILES main.cpp)
add_executable(bgfx_test ${SOURCE_FILES})

add_subdirectory("thirdparty/bgfx.cmake")

after that i tried to set it up with fips which worked after i added a few symlinks to the dependencies

(stuff like linking libXinerama.so to libXinerama.so.1 because fips could not find it with the '.1' at the end)

so now i can run the examples and even setting up the project on windows worked - at least for the examples.

but i'd really like to not write my application in the "bgfx/exampels" folder

but i cant get it to work outside of it, even when setting up this way

edit

since it seemed not to be clear enough:

My questions:

  • Why do i get the unresolved reference error? it does not make sense at all to me.
  • When setting up bgfx on windows (like in the documentation) or via fips, how can i make it work without writing my code in the "examples" folder of a third party library?

it would be wonderful to see a CMakeLists.txt for a tiny example, or just tell me whats wrong with mine


edit 2 (27.05.2017):

after i added

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

to my CMakeLists.txt i get the next 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

where the only useful hit google produces is this but it is unanswered :/

Community
  • 1
  • 1
Soraphis
  • 706
  • 7
  • 26
  • Do you want someone to **write** skeleton example for `bfgx`? This would be too broad. Do you want to help with **existing** example? Then you need to provide its code. Also, at the end of the question post you seem to resolve the problem. So, what do you want **exactly**? – Tsyvarev May 26 '17 at 11:50
  • i tried to clarify it a bit: i just want to use bgfx as a third party app, not writing my code in their examples folder. i want to know why my IDE can resolve everything, but the compiler throws an error. why is it inherently hard to set up c++ projects with third party software? – Soraphis May 26 '17 at 12:15
  • 1
    When autocomplete, IDE looks for header which *declares* the function. Error "unresolved reference" means that **definition** of the function is not found. Functions are defined in the `.c` code or in the library you link with. – Tsyvarev May 26 '17 at 21:22

1 Answers1

6

it worked with this CMakeLists.txt:

cmake_minimum_required(VERSION 3.7)
project(bgfx_test)

set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)

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

target_link_libraries(bgfx_test bgfx example-common)
Soraphis
  • 706
  • 7
  • 26