GLBasic forum

Main forum => Bug Reports => Topic started by: Schranz0r on 2020-May-02

Title: Code seperate from headerfile (.h and .cpp) -> no reference to function...
Post by: Schranz0r on 2020-May-02
Hi,

simple to reproduce:

test.h:
Code: (glbasic) [Select]
int addStuff(int x, int y);
}

test.cpp:
Code: (glbasic) [Select]
#inlude "test.h"

int addStuff(int x, int y) {
return x + y;
}


glbasic:
Code: (glbasic) [Select]
INLINE
}
#include "test.h"

namespace __GLBASIC__{
ENDINLINE

FUNCTION TEST_addStuff: x, y
INLINE
return addStuff(x, y);
ENDINLINE
ENDFUNCTION


Result:
undefined reference to `addStuff(int, int)'

cpp-files seems to be ignored!

Is this new or i be stupid right now?!
Title: Re: Code seperate from headerfile (.h and .cpp) -> no reference to function...
Post by: Qedo on 2020-May-02
so it works:

test.cpp:
Code: (glbasic) [Select]
extern "C"    int addStuff(int x, int y) {
return x + y;
}


GlBasic
Code: (glbasic) [Select]
REQUIRE "test.cpp"
IMPORT "C" int addStuff(int x, int y)
PRINT addStuff(1340,220),60,50
SHOWSCREEN
SLEEP 6000
END
Title: Re: Code seperate from headerfile (.h and .cpp) -> no reference to function...
Post by: Schranz0r on 2020-May-02
I know but make no sens...
On my project i get multiple errors with this method ^^

Attached the GLFW and ImGUI Project...
Error on IMGUI.gbas :/

EDIT: To run correctly you have edit Projects->Options->INK the Path to the folder!
Title: Re: Code seperate from headerfile (.h and .cpp) -> no reference to function...
Post by: dreamerman on 2020-May-03
Nice inline stuff, but that quest is to hard and this ImGui library looks strange, so many build/include options oh..
Briefly looked at it, and from one hand it doesn't have it's own lib/a file, but when checking some makefiles that people are using to build apps with it - they are including main cpp files as a library:
for example:
Quote from: https://github.com/lucasw/imgui_ros/blob/master/imgui_ros/CMakeLists.txt
add_library(${PROJECT_NAME}
  src/dynamic_reconfigure.cpp
  src/imgui_ros.cpp
  src/image.cpp
  imgui/imgui.cpp
  imgui/imgui_demo.cpp
  imgui/imgui_draw.cpp
  imgui/imgui_widgets.cpp
  imgui/examples/imgui_impl_sdl.cpp
  imgui/examples/imgui_impl_opengl3.cpp
  imgui/examples/libs/gl3w/GL/gl3w.c
)
and somwehere there is also: "/devel/lib/libimgui/imgui.cpp.so" so it look's like sources need to be compiled as lib file or included somehow in link stage...
Checked some tutorials for that lib, it should be easy to use it, but all of them are using makefiles, not direct g++ command lines. That's best in such solutions, over complicating simple thing in a way so it's hard to bite it..

btw. inline in GLB can be tricky :D