Hi, I've been looking for a couple days and can't find out exactly how this is
done. Goal: have cpp/h files generated that I can compile in with my c++
project to include helper functions originally written in nim. I'll try
updating to development later to see if that fixes it.
What I'm doing:
$ nim cpp -c -d:release --header --noMain mylib.nim (see below for src)
$ cd nimcache
$ ls
main.cpp (see below for src)
mylib.cpp
mylib.h
<redacted usual nim cpp files>
$ g++ -o main *.cpp -I/Nim-0.18.0/lib -w
stdlib_dynlib.cpp: In function 'void*
symAddr_NHfjIU1Uh0ju9azgMjiSkQA(void*, NCSTRING)':
stdlib_dynlib.cpp:45:25: error: invalid conversion from 'FARPROC' {aka
'long long int (*)()'} to 'void*' [-fpermissive]
result = GetProcAddress(LOC1.dest, name);
$ gcc --version
<...> 8.2.0
Run
// main.cpp
#include <iostream>
#include "mylib.h"
using namespace std; // for demo
extern char** parseCSVListLine(const char*); // Seem to need this because
mylib.h does not have it (?!)
int main() {
parseCSVListLine("one,two,three");
return(0);
}
Run
import strutils, sequtils, os, parsecsv, streams, future
proc parseCSVListLine*(str: string):seq[string] =
var ss = newStringStream(str)
var p: CsvParser
p.open(ss, "parseCSVListLine()")
discard p.readRow()
return lc[ col.strip() | (col <- items(p.row)), string]
proc parseCSVListLine*(str: cstring):cstringArray {.extern:
"parseCSVListLine".} =
return alloccstringArray(parseCSVListLine($str))
Run