Immediate-Mode-UI / Immediate-Mode-UI/Nuklear
Cannot compile sample project with nuklear
- Dominant language
- C
- Stars
- 11.4k
- Forks
- 686
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 3
Description
Hi there,
ich have an annoying issue with compiling the sample project, which I canot get rid of. My project structure looks like this:

with the ```nuklear``` directory being the freshly downloaded and extracted copy of the nuklear repository.
the ```CMakeLists.txt``` is:
```
cmake_minimum_required(VERSION 3.20)
project(nuklearTest)
set(CMAKE_CXX_STANDARD 14)
add_executable(nuklearTest main.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/nuklear)
```
here's my main.cpp:
```
#include
#include "nuklear.h"
int main()
{
/* init gui state */
struct nk_context ctx;
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
enum {EASY, HARD};
static int op = EASY;
static float value = 0.6f;
static int i = 20;
if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
/* fixed widget pixel width */
nk_layout_row_static(&ctx, 30, 80, 1);
if (nk_button_label(&ctx, "button")) {
/* event handling */
}
/* fixed widget window ratio width */
nk_layout_row_dynamic(&ctx, 30, 2);
if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;
/* custom widget pixel width */
nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
{
nk_layout_row_push(&ctx, 50);
nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
nk_layout_row_push(&ctx, 110);
nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
}
nk_layout_row_end(&ctx);
}
nk_end(&ctx);
}
```
First, I am missing references to the constant MAX_MEMORY and &font. I have manually created them at the beginning of the main.cpp function like this (I don't know if that's correct, but at least the CLion IDE doesn't complain anymore):
```
const int MAX_MEMORY = 128;
nk_user_font font = (const nk_user_font&)"Times New Roman";
```
but now I encounter the error:
```main.cpp.obj : error LNK2019: unresolved external symbol nk_init_fixed referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_begin referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_end referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_layout_row_dynamic referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_layout_row_static referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_layout_row_begin referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_layout_row_push referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_layout_row_end referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_label referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_button_label referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_option_label referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_slider_float referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol nk_rect referenced in function main
nuklearTest.exe : fatal error LNK1120: 13 unresolved externals
```
I am quite sure the ```nuklear.h``` is correctly linked, as I can implement other functions from within the IDE. I already played around with other CMake commands, like ```include_directories``` in order to find nuklear, but to no avail. I have also tried to include:
```
#define NK_IMPLEMENTATION
#include "nuklear.h"
```
Then, the project compiles but I get this error during execution:

There must be something I am missing. Any help is welcome. Thanks
Contributor guide
Research direction
Reproduce the sample using CMakeLists.txt and main.cpp, then inspect how nuklear.h is included and built. Compare the linker errors with the NK_IMPLEMENTATION attempt and investigate the reported runtime failure; done means the sample builds and runs without those errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100