how to setup nuklear in a visual studio(2019) c project?

922 Views Asked by At

I have tried two methods to the best of my capacity:

  1. One A solution containing two projects Nuklear and Nuklear Test. Nuklear contains all of its c files and headers. Then it compiles into a static lib and have added it has reference in Nuklear Test.
  2. All of them in one project- the demo files and files of nuklear library.

Both of them don't work

I have additionally linked following .lib for x64 Debug in both the cases:

  1. opengl32.lib
  2. glew32sd.lib
  3. glfw3.lib

I think the main errors I get are:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol NK_MEMCPY    NuklearTest D:\vs_project\NuklearT\NuklearTest\NuklearTest\Nuklear.lib(nuklear_buffer.obj)  1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol NK_MEMSET    NuklearTest D:\vs_project\NuklearT\NuklearTest\NuklearTest\Nuklear.lib(nuklear_context.obj) 1   
1

There are 1 best solutions below

0
On

Nuklear is self-contained in a single header file. The files in src aren't designed to be built directly and should be packed into the proper library header via src/paq.bat or src/paq.sh, this means that src/nuklear.h should not be included in your projects. A pre-built header that you could use without having to run any scripts whatsoever is in the project's main directory.
If you'd like to static link this library just build the packed header and then link it in your project.

How to include the library for building

nuklear.h can be included in either implementation mode or header-only mode, the former must be only included once otherwise there'll be several linking errors and the latter can be used when including in other files. Also before every inclusion of the header all the optional flags should be redefined.
To include it in implementation mode the macro NK_IMPLEMENTATION should be defined before including it.

#define NK_IMPLEMENTATION //< Include nuklear in implementation mode
#include "nuklear.h"

It's not required to link any other libraries, when using any of the functions of Nuklear. But in order to render anything a backend is needed, e.g. OpenGl or Allegro5, and it should be set up as you would in any other applications.

How to use the library in your project

Abstractions aren't provided for render/event backends (no direct OS or window handling is done by the library), this means that any backend can be used to render the GUI generated by Nuklear not only the default ones provided by your system. Look in the API documentation for how to implement the rendering 'engine' and the input handling of your project.
There are several demonstrations in demo for different backends. Those demo headers can be included in your project for most of the handling, and the remaining can be adapted from the main.c file in the directory.
There are also examples of how to use each of the features in this folder (especially in demo/overview.c).