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

Previous topic - Next topic

Schranz0r

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?!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Qedo

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


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!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

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.txtadd_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
Check my source code editor for GLBasic - link Update: 20.04.2020