C lib unresolved external symbols
Hey - I'm trying to link to inkcpp_c.lib and running into unresolved external symbols (attached). Any help would be very much appreciated!
I also tried building a dynamic library version of the cpp lib but I get:
runner_impl.obj : error LNK2019: unresolved external symbol "char const * * ink::CommandStrings" (?CommandStrings@ink@@3PAPEBDA) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl ink::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,enum ink::Command)" (??6ink@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV12@W4Command@0@@Z)
6>P:\projects\InkCpp\build\inkcpp\Release\inkcpp.lib : fatal error LNK1120: 1 unresolved externals
The linking is part of the ink.json → inkcpp.bin conversion.
Would you mind expanding further on how exactly your build process is?
I did not encounter the error when using the steps below. (which does not mean you should change your approach, just that I can't reproduce it)
If I use the win64_clib.zip with a dummy test.c
I can compile it with cl /EHsc test.c lib\ink\inkcpp_c.lib /link /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib
And run it:
.\test.exe
> start
> compiled
> First line has global tags only
> Second line has one tag
> Third line has two tags
> Fourth line has three tags
> Hello
> Second line has no tags
test.c
#include "include/ink/inkcpp.h"
#include <stdio.h>
int main() {
fprintf(stderr, "start\n");
ink_compile_json("story.ink.json", "story.bin", NULL);
fprintf(stderr, "compiled\n");
HInkStory* story = ink_story_from_file("story.bin");
HInkRunner* thread = ink_story_new_runner(story, NULL);
while(ink_runner_can_continue(thread)) {
printf("%s", ink_runner_get_line(thread));
}
}
I'm actually generating bindings for a different language (JAI) and trying to use it in my application. I'm able to generate the bindings, but running into the linker issues in my app. You mentioned that these are coming from the compiler though - do I need that for the runtime or just for compiling json to the binary format (which I could do separately?)
Maybe I'm linking the compiler somehow and I can just skip that? 🤞
It is just for converting JSON to binary.
The array which is failed to link is in inkcpp_compiler/command.cpp
The compiler is included in inkcpp_c/inkcpp.cpp:14 and used in inkcpp_c/inkcpp.cpp:ink_compile_json
If you remove this lines and remove the linkage in cmake inkcpp_c/CMakeLitst.txt:11 and inkcpp_c/CMakeLists.txt:3 You should get it.
If you need the changed lib files:
clib.zip
The changes as patch inkcpp_c_without_compiler.patch git apply inkcpp_c_without_compiler.patch
Please let me know if this was helpful.
I used the attached clib.zip and commented out the ink_compile_json stub in incpp.h. I'm not getting the unresolved symbols for the compiler but still getting the rest. Did the attached clib have the modified .lib file?
I also tried compiling it (with the changes you suggested) but I'm not sure how to generate the clib.
Yes, the club is with the modifications incorporated.
So yeah it works
To build the clib you need to set INKCPP_C=On
Either with cmake-gui or cmake -DINKCPP_C=ON.
Let me know if you need more guidance, I'm happy to help.
Going forward do you think, this is something more people are interested in?
If yes we could introduce a new compile option (eg INKCPP_C_WITH_COMPILER) which is enabled as default.
I re-cloned the repo and was able to build the clib with that cmake option (and the patch). I tried generating bindings again using it and still getting unresolved symbols (attached). I really appreciate the help. ❤️
I do think more people would be interested in this, both in the Jai community and in the Raylib community (which a lot of users create raylib projects using different languages). If the compiler can be used separately from the runtime, then users could just use the compiler to generate the binaries from Inky output. Having a standalone clib runtime that works natively with raylib or other languages would really expand the users!
Ok, I'm on it. I missed a few standard library references in the code; at least in my test environment, it is down to 11 (from 91), so maybe when I push it, you also got rid of a few ^^
Thank you for your feedback. ^^
I did some changes and was able to build it completely without CSTD libs (I think) at this branch
The required cmake variables/options are
-
-DINKCPP_C -
-DINKCPP_NO_STL
And if you then build a release, there should not be any magic left to fail to bind.
A problem is then that the _from_file function does not work any longer, since it uses fopen.
This was my test programm
#include "include/ink/inkcpp.h"
#include <stdlib.h>
#include <stdio.h>
int main() {
fprintf(stderr, "start\n");
FILE* file = fopen("story.bin", "rb");
fseek(file, 0, SEEK_END);
long size = ftell(file);
fseek(file, 0, SEEK_SET);
unsigned char* data = (unsigned char*)malloc(size);
fread(data, sizeof(unsigned char), size, file);
fclose(file);
HInkStory* story = ink_story_from_binary(data, size, true);
HInkRunner* thread = ink_story_new_runner(story, NULL);
while(ink_runner_can_continue(thread)) {
printf("%s", ink_runner_get_line(thread));
}
ink_runner_delete(thread);
ink_story_delete(story);
}
Hey! I got back to working on this and I think I've got it working now. I was able to run the crime scene example from Ink's documentation, so hopefully that means its good to go! Again I really appreciate the help and I'll keep you posted if I run into any snags as I start integrating this into my project.
Perfect, I will then close the issue for now; feel free to reopen it