Comments (5)
- Don't use
push
/pop
for specifying header, put it as a pragma in the corresponding proc/type. - .importcpp expects pattern as a value.
- Use
.compile
pragma to compile .cpp file along with Nim files. - Use
--cincludes:DIR
to specify where to look for the header file.
This information can be found in the Nim manual.
Try this:
{.compile: "FastNoise.cpp".}
type
FastNoise* {.header: "FastNoise.h", importcpp: "FastNoise".} = object
proc GetValue*(this: FastNoise, x: cfloat, y: cfloat): cfloat {.header: "FastNoise.h", importcpp: "#.GetValue(@)".}
from godot-nim.
- Ok, but why?
- I thought the name is taken from the procedure name and you only need it when you want a different name?
- gotcha
- im having problems with this
i did a quick test with a simple non godot project with a structure like so:
C:/Test/main.nim
C:/Test/fastnoise.nim
C:/Test/lib/FastNoise.h
C:/Test/lib/FastNoise.cpp
fastnoise.nim has the code you have kindly posted, then i use
nim c --cincludes:"C:\Test\lib\" --run "C:\Test\main.nim"
i get this error:
Error: unhandled exception: cannot open: FastNoise.cpp [IOError]
It's beginner level, i know :) but working with godot and external libs is important for me, i need to get this going. I want to take a switch from C# godot because i really like nim so far.
And in an actual godot project, how to use --cincludes with "nake build"? maybe in the nakefile.nim somewhere? or do i need to compile it once with nim?
thanks for your time
from godot-nim.
ok, im one step further.
cincludes only with root folder
nim c --cincludes:"C:\Test" --run "C:\Test\main.nim"
and in fastnoise.nim the subfolder:
{.compile: "lib/FastNoise.cpp".}
new error:
In file included from C:\Test\nimcache\main.c:11:0:
C:\Test/lib/FastNoise.h:45:1: error: unknown type name 'class'
class FastNoise
^~~~~
C:\Test/lib/FastNoise.h:46:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
{
^
C:\\Test\nimcache\main.c: In function 'GetNoise_9cku33tvANHm87a2gL2qUHQ':
C:\\Test\nimcache\main.c:80:2: error: unknown type name 'FastNoise'
FastNoise obj;
^~~~~~~~~
C:\\Test\nimcache\main.c:87:11: error: request for member 'GetValue' in something not a structure or union
T2_ = obj.GetValue(5.0000000000000000e+000, 8.0000000000000000e+000);
from godot-nim.
godot-nim-stub
sample uses C backend to compile the code. You need to modify it to use C++. The line that compiles the main file is the last one in the build
task of the nakefile: https://github.com/pragmagic/godot-nim-stub/blob/54e5d5c2526262b6e3a0b293676465b5bf615b88/nakefile.nim#L45
Change c
to cpp
and add any other parameters you need.
Re push/pop, I think they simply don't work in a way you used them. They can be used to override compiler settings, but not to assume that everything has a certain pragma on it.
And yeah, if you duplicate names it isn't necessary to specify them as .importcpp pragma values, but to be consistent with Nim style it's better to change the method name to lowercase. So in the end you should have something like this:
{.compile: "lib/FastNoise.cpp".}
type
FastNoise* {.header: "FastNoise.h", importcpp.} = object
proc getValue*(this: FastNoise; x, y: cfloat): cfloat {.header: "FastNoise.h", importcpp: "GetValue".}
It's been a while since I last dealt with C++ interop, so might be something else that's needed here.
from godot-nim.
ok, fixing the test project above was simple, c
to cpp
nim cpp --cincludes:"C:\Test\lib\" --run "C:\Test\main.nim"
is working, GetValue does its job, nice
now to godot, not so easy though :/
changing c
to cpp
only gives error LNK2019: unresolved external symbol
and nim64.dll: Fatal Error LNK1120: 1 unresolved externals
also Error: execution of an external program failed: 'vccexe.exe
im not importing fastnoise at all, just changing to cpp
from godot-nim.
Related Issues (20)
- Nim constructor not found for class BulletPhysicsDirectSpaceState HOT 1
- Issue with connecting signal BodyEntered (area) HOT 1
- Generate .dll for other platforms (like Linux) HOT 4
- New native extension system for 4.0 HOT 1
- Basis getEuler behavior
- Add proc directionTo for vector2 and vector3
- GDExtentions Support HOT 1
- Nake Build Error HOT 14
- Nake build failed if GODOT_BIN path contains space character
- How to deal with exceptions? (and other beginner notes) HOT 7
- Documentation search doesn't do anything
- Export questions HOT 2
- Is this abandoned? What's happening HOT 4
- nake build error:: type expected but got symbol 'Array' of kind 'enumField' HOT 2
- godot-nim crashing godot (windows 10) [Solved?]
- I can't find the answers
- Error: type expected, but got symbol 'Array' of kind 'enumField' HOT 1
- is this abandoned? HOT 7
- Output is flooding with `A foreign thread is created` when i use NavigationAgent
- Cant compile to wasm
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godot-nim.