Main forum > Bug Reports

Code seperate from headerfile (.h and .cpp) -> no reference to function...

(1/1)

Schranz0r:
Hi,

simple to reproduce:

test.h:

--- Code: (glbasic) ---int addStuff(int x, int y);
}
--- End code ---

test.cpp:

--- Code: (glbasic) ---#inlude "test.h"

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


glbasic:

--- Code: (glbasic) ---INLINE
}
#include "test.h"

namespace __GLBASIC__{
ENDINLINE

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


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

cpp-files seems to be ignored!

Is this new or i be stupid right now?!

Qedo:
so it works:

test.cpp:

--- Code: (glbasic) ---extern "C"    int addStuff(int x, int y) {
return x + y;
}
--- End code ---


GlBasic

--- Code: (glbasic) ---REQUIRE "test.cpp"
IMPORT "C" int addStuff(int x, int y)
PRINT addStuff(1340,220),60,50
SHOWSCREEN
SLEEP 6000
END
--- End code ---

Schranz0r:
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!

dreamerman:
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
)
--- End quote ---
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

Navigation

[0] Message Index

Go to full version