go-sciter icon indicating copy to clipboard operation
go-sciter copied to clipboard

Linking Sciter statically

Open inkeliz opened this issue 6 years ago • 45 comments

If I have an "INDIE" (or greater) license I'm allowed to "Linking Sciter statically". It's suported by go-sciter?

inkeliz avatar Feb 20 '18 05:02 inkeliz

I think, you can specify CGO_CFLAGS=-DSTATIC_LIB , CGO_LDFLAGS=-lsciter-win-64 and recompile go-sciter package.

pravic avatar Feb 20 '18 09:02 pravic

Does this mean without a license of some sort you have to have the person you give your application to install sciter? Also the "INDIE" one only supports Windows?

gcstang avatar Feb 20 '18 23:02 gcstang

It is better to ask such questions on forum: https://sciter.com/forums

pravic avatar Feb 21 '18 06:02 pravic

@pravic how do you or others package the library normally?

gcstang avatar Feb 21 '18 16:02 gcstang

Just put a sciter dll/so/dylib near the executable. HTML/CSS/Tis files either in their own folder or linked into executable. Or just in zip archive.

pravic avatar Feb 21 '18 17:02 pravic

@pravic do you then have the user add it to the environment or load it somehow in a relative way from the program?

gcstang avatar Feb 21 '18 17:02 gcstang

Yes, correct. Or just like this where dlls in the same directory as executables: https://github.com/c-smile/sciter-sdk/tree/master/bin.gtk

pravic avatar Feb 22 '18 08:02 pravic

@pravic I'm really new to the go language, would you have an example of how you're loading it from a relative path that you could share?

gcstang avatar Feb 22 '18 14:02 gcstang

If you are talking about how to load libsciter using relative path, right now it is not possible, because it is hardcoded to be loaded either from current directory or from the system PATH:

https://github.com/sciter-sdk/go-sciter/blob/8b236559b9ac242721e96957c71469fd9d21c1a8/sciter-x-api.c#L22-L27

What are you trying to achieve? It would be easier to give a more suitable answer.

pravic avatar Feb 22 '18 14:02 pravic

@pravic ah I see the issue now, I'm on a Mac and that snippet isn't loading for MacOS only Windows and Linux. The lib for Mac is sciter-osx-64.dylib

gcstang avatar Feb 22 '18 14:02 gcstang

For OSX it loads from the following paths:

https://github.com/sciter-sdk/go-sciter/blob/8b236559b9ac242721e96957c71469fd9d21c1a8/sciter-x-api.c#L75-L80

where "/" is relative to your executable.

pravic avatar Feb 22 '18 14:02 pravic

@pravic thank you, have it working now. I must have tried it before in a different location, my apologies and thank you for this project.

gcstang avatar Feb 22 '18 15:02 gcstang

thank you for this project

It was not me. Andrew @c-smile is the only author of the Sciter engine. @oskca has created Go bindings.

I am just a maintainer of binding libraries :)

pravic avatar Feb 22 '18 15:02 pravic

It doesn't work, not using the -DSTATIC_LIB, it returns:

sciter-x-api.c: In function 'SAPI':
sciter-x-api.c:15:20: error: expected expression before ':' token
           tiscript::ni( _api->TIScriptAPI() );

https://github.com/sciter-sdk/go-sciter/blob/master/sciter-x-api.c#L15

inkeliz avatar Mar 20 '18 07:03 inkeliz

@Inkeliz True, it was C++ portion. I've pushed a fix.

pravic avatar Mar 20 '18 08:03 pravic

Well, it fix the problem, but I think have another error. :'(

In my case it returns some warnings:

sciter-x-api.c: In function 'SAPI':
sciter-x-api.c:14:34: error: 'nullptr' undeclared (first use in this function)
        static ISciterAPI* _api = nullptr;
                                  ^~~~~~~
sciter-x-api.c:14:34: note: each undeclared identifier is reported only once for each function it appears in
sciter-x-api.c: At top level:
sciter-x-api.c:14:27: warning: '_api' is static but declared in inline function 'SAPI' which is not static
        static ISciterAPI* _api = nullptr;
                           ^~~~

The compilation didn't work at all.

inkeliz avatar Mar 20 '18 12:03 inkeliz

@Inkeliz Yeah, sorry, I have missed it :)

pravic avatar Mar 20 '18 14:03 pravic

Well, one error was remove, but seems one continue, with more explanation:

# github.com/sciter-sdk/go-sciter
C:\Users\Inkeliz\AppData\Local\Temp\go-build523114306\b126\_x007.o: In function `SAPI':
..\..\sciter-sdk\go-sciter/sciter-x-api.c:18: undefined reference to `SciterAPI'
..\..\sciter-sdk\go-sciter/sciter-x-api.c:18: undefined reference to `SciterAPI'
..\..\sciter-sdk\go-sciter/sciter-x-api.c:18: undefined reference to `SciterAPI'
..\..\sciter-sdk\go-sciter/sciter-x-api.c:18: undefined reference to `SciterAPI'
..\..\sciter-sdk\go-sciter/sciter-x-api.c:18: undefined reference to `SciterAPI'
C:\Users\Inkeliz\AppData\Local\Temp\go-build523114306\b126\_x007.o:E:\Documentos\GoProjects\src\github.com\sciter-sdk\go-sciter/sciter-x-api.c:18: more undefined references to `SciterAPI' follow
collect2.exe: error: ld returned 1 exit status
# github.com/sciter-sdk/go-sciter
sciter-x-api.c:14:27: warning: '_api' is static but declared in inline function 'SAPI' which is not static
        static ISciterAPI* _api = 0;
                           ^~~~

I don't know if I'm doing something wrong, I'm changing this line, also I change this, for testing. I test to append the -DSTATIC_LIB, or only with -DSTATIC_LIB and so on. But always gets some error. :'(

inkeliz avatar Mar 20 '18 15:03 inkeliz

STATIC_LIB define means that SciterAPI function is defined in sciter's static library that needs to be linked with your executable. You need a) access to sciter sources, b) build that static lib ({sciter-src-root}/lib/Release/sciter-win-64.lib) and c) include that lib into linkage list of your application.

c-smile avatar Mar 20 '18 16:03 c-smile

include that lib into linkage list of your application

@Inkeliz That said, you need to set something like:

set CGO_CFLAGS=-DSTATIC_LIB
set CGO_LDFLAGS="-lsciter-win-64 -LC:/path/to/static/build"
go build -a

including requirements mentioned by Andrew, of course.

pravic avatar Mar 20 '18 19:03 pravic

don't know if I'm doing something wrong, I'm changing this line, also I change this, for testing.

@Inkeliz if you want to test it, compile the following code into a static library and try to link it with go-sciter:

// test.c
void* __stdcall SciterAPI(void) { return 0; }
$ cl.exe /c test.c
$ lib.exe test.obj /out:sciter-win-64.lib

Then set the CGO flags above and try to recompile go-sciter/examples/simple. It should be compiled without errors and after run you should see something like:

File: sciter-x-api.c, Line 23 Expression: _api

as a result of the assert from the sciter-x-api.c: https://github.com/sciter-sdk/go-sciter/blob/57abd660ac262f4cda570bd6c7d390395946ae03/sciter-x-api.c#L23-L24

And if you remove CGO flags and recompile it again, you'll see a normal example window, as usual.

pravic avatar Mar 20 '18 19:03 pravic

Finally, I could compile the Sciter and gets the lib.

But using the same command mentioned by @pravic it returns:

# runtime/cgo
gcc: error: "-lsciter-win-64: Invalid argument

inkeliz avatar Mar 20 '18 23:03 inkeliz

You are compiling static lib using Microsoft Visual C++. And trying to use in with gcc, right?

If "yes" then this may not work - at least I haven't heard about successfull attempts of doing so.

c-smile avatar Mar 20 '18 23:03 c-smile

Yes. So, that is impossible? :
Can I compile the lib with GCC, or something compatible?

inkeliz avatar Mar 20 '18 23:03 inkeliz

http://www.mingw.org/wiki/Interoperability_of_Libraries_Created_by_Different_Compiler_Brands

c-smile avatar Mar 20 '18 23:03 c-smile

Theoretically possible but practically - not.

c-smile avatar Mar 20 '18 23:03 c-smile

I am compiling sciter on Linux using GCC so source code is GCC compatible. But I haven't done this on Windows. Had no reason of doing so.

c-smile avatar Mar 20 '18 23:03 c-smile

My knowledge about GCC, and Microsoft Visual C++, is close to zero. Do you think that is possible to compile using GCC on Windows? If I compile using linux, can I create the executable on Windows, with the same "lib"?

I really don't know anything about it, I just literaly wanted to "hide" de .dll. :\

inkeliz avatar Mar 21 '18 00:03 inkeliz

Do you think that is possible to compile using GCC on Windows?

I think so. It will take some time but feasible. To create make/CMakeFile using VS project as a prototype, it will be quite time consuming though. In principle there are tools that can convert VS projects to CMake files: https://cmake.org/Wiki/CMake#Visual_Studio With CMake files you may generate make files for GCC.

But even that....

There are two GCC toolchains on Windows: GCC/MinGW and GCC/Cygwin. They use incompatible runtimes... What version of GCC your host application is using?

c-smile avatar Mar 21 '18 00:03 c-smile

I'm using the MinGW, which is mentioned on README. To be precise, I'm using "x86_64-w64-mingw32 6.3.0".

I'll take a look on that. But, I'm closer to give up about this idea, at least for now. I think have another alternative to, even if not the best solution, it will achieve the same goal. My goal is a way to "hide" the .dll only having the .exe.

inkeliz avatar Mar 21 '18 01:03 inkeliz