Closed ghost closed 6 years ago
Hey @bentxt,
If you're getting to the linker stage then you're nearly there. You're right that the missing symbols indicate the hashlink library isn't being linked.
Have you compiled a libhl.dylib (macOS) or libhl.so (linux)?
If not run make libhl
in the root of this repository
Once you've got a libhl.*, run make install_lib
to copy it to the system lib search path (/usr/local/lib
on macOS), then you can add -lhl
to your gcc command and it'll link with the libhl.* you built.
(If you're still getting undefined symbols then check the top of your gcc output for anything like cannot find library hl
and try to figure out why the compiler can't find it)
At the moment you've got a -Lhl
flag which adds a library search path to the gcc command which might not be what you want. Lowercase 'L' is needed to specify a library to link with
I think automatic native compilation is still in the pipes so for the time being it requires a bit of figuring out how to compile it yourself
Additionally, you can resolve your first issue about missing headers by adding an include flag to the GCC command- like -I hashlink/src
(but substitute your own path to hashlink repo)
Thanks for your help. Let me document the whole process. Maybe I put it somewhere.
Requirements:
haxelib install hashlink
git clone https://github.com/HaxeFoundation/hashlink.git
cd hashlink
make
sudo make install_lib
then leave the project:
cd ..
then with hello.hx:
class Hello {
static function main() {
trace("Hello World!");
}
}
Compile to c with haxe (hashlink) and then to native with gcc:
haxe -hl hello.c -main Hello
gcc -o hello -D INCLUDE_ALL -I . -I hashlink/src -std=c11 hello.c -lhl
./hello
Hello.hx:3: Hello World!/hello
System information:
haxe -version
4.0.0 (git build development @ a018cbd)
gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Yes I need to update the website, the instructions are outdated because they were for 3.4 and we changed things for 4.0 Will maybe wait a few more weeks
On Tue, Oct 24, 2017 at 12:43 PM, bentxt notifications@github.com wrote:
Thanks for your help. Let me document the whole process. Maybe I put it somewhere. Run a hello world with the C backend of Hashlink:
git clone https://github.com/HaxeFoundation/hashlink.git cd hashlink make sudo make install_lib
then leave the project: cd .. then with hello.hx:
class Hello { static function main() { trace("Hello World!"); } }
Compile to c with haxe (hashlink) and then to native with gcc:
haxe -hl hello.c -main Hello
gcc -o hello -D INCLUDE_ALL -I . -I hashlink/src -std=c11 hello.c -lhl
./hello Hello.hx:3: Hello World!/hello
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hashlink/issues/86#issuecomment-338949782, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-bwFvbbq9lygYpzmiFrw0gkr1EX-Ucks5svb9ZgaJpZM4QEA2t .
I have added make install
that install both libs and headers on the system. ATM is uses/usr/lib
and /usr/include
because Ubuntu does not have /usr/local
by default (I think). Maybe we should use /opt/local
for OSX ? ping @andyli
/usr/local
is the right prefix to use. Common practice is to create it if it doesn't exist, and it's what the haxe Makefile does: https://github.com/HaxeFoundation/haxe/blob/3.4.4/Makefile#L125
hi,
I cannot compile the hl/c output of this simple hello.hx:
Compile to hl/c works:
$ haxe -hl hello.c -main Hello
Now comes the part, where the tutorial is not working anymore:
gcc -o hello -D INCLUDE_ALL -std=c11 hello.c -Lhl
This gives the error:
After copying some files from ./src like hl.h, hlc.c, hlc.h, hlc_main.c, there are no missing errors when I include the 'hl' directory and the root directory '.':
gcc -o hello -D INCLUDE_ALL -I hl -I . -std=c11 hello.c -Lhl
But then get a lot of 'Undefined symbols' error, a sign that the library probably cannot be found.
So what to do for this simple hello world?