Hi, this looks like a codegen issue, but wanted to ask as I might be missing something simple. The code will only run if the type declaration is removed from the first file, however if I put that line into my main file, then everything compiles okay, and I can even use the type. (I tried searching the codegen issues this time)
EDIT/SOLUTION: Araq pointed out what I was forgetting: that using importcpp means I should also compile to produce cpp code with 'nim cpp'. This is a little confusing since some cpp code is generated already in nimcache, so I didn't even think of this. Maybe it would be useful to throw a warning in these cases.
Tested on:
File1: importme.nim
## Random Device from C++
type TRandomDevice*
{.importcpp:"std::random_device", header:"<random>".} = object
proc dothis*() =
echo "ran the 'dothis' fn"
File2: main.nim
import importme
dothis()
Clang Linker Error
Undefined symbols for architecture x86_64: │~
"_dothis_A9crgxPxoHyUlNFt9aA8PinQ", referenced from: │~
_NimMainModule in testseq.o │~
ld: symbol(s) not found for architecture x86_64
Resolved. I didn't not understand when to use importc vs importcpp. Apparently importcpp is ONLY for methods of classes. If I change my pragma to importc then everything is fine.
-From docs/backends.html-
"The importc pragma is the generic way of making backend
symbols available in Nim. The C++ or Objective-C backends
have their respective ImportCpp and ImportObjC pragmas
to call methods from classes."
EDIT: This is wrong. It doesn't let me use the type, since the c compiler of course "can't find the file random in #include <random>"
@ggibson, I was able to run your first example (the "importcpp") with additional
{.passC: "-Inimcache".}
at the very top of main.nim .
I don't know why but the error (the cannot find symbol error) was generated because nimcache folder wasn't included in path, so you need to add passC pragma.
Oh, I'm using vcc, I still haven't tried using clang.
Edit: Not sure why, but now it's working without passC pragma, why did it trigger the error in the first place?