<FromGitter>
<johnjansen> thanks @Papierkorb, one question … where does the C code live
<Papierkorb>
In the above example, I just link against libLua, so I didn't have to write any C code. Though, in your case, you'd link a shared library and then do something very similar
soveran has joined #crystal-lang
<FromGitter>
<johnjansen> yeah, thats the stuff i kinda want to see, like a tiny project with some c code and the crystal bindings, so i can figure that stuff out
<Papierkorb>
Most likely you'll put a "nicer" high-level API abstraction on top of it.
<Papierkorb>
johnjansen, the structure ruby gems use is fine imho
<FromGitter>
<jwoertink> One question I've always had though is *where* those links are. Like in the case of `@[Link("lua")]`, is this looking for a `lua.h` somewhere in the `$PATH`?
<FromGitter>
<johnjansen> thats exactly my point @jwoertink ⏎ given i dont have alot of time to figure all this out, amongst my real work ;-)
<FromGitter>
<jwoertink> I just don't know anything about C or C++ to understand what "linking" means. lol
<FromGitter>
<jwoertink> I would love to see a in-depth guide on building a shard that wraps some C lib or extends one.
<FromGitter>
<johnjansen> agreed, although in the absence of that, a hello world would be a great start
<Papierkorb>
jwoertink, TL;DR: A compiler compiles the code to an object file. These end in .o - Now you need a linker, which takes all object files and "translates" them into something you can actually execute. You can also link into a shard lib. It's not a "link"
<Papierkorb>
johnjansen, linkers/compilers use search paths to find the referenced library. when I link against "lua", it'll search for a file named liblua.so or liblua.a in different paths, including /usr/lib on most UNIX (?) systems, which contains most libraries you have on your system
<FromGitter>
<jwoertink> Ah, ok. Awesome. Well that's definitely a start!
pawnbox has quit [Remote host closed the connection]
<Papierkorb>
jeez now I even begin typing the wrong nicks cause the bridge breaks nick tabbing. sorry johnjansen.
<FromGitter>
<johnjansen> thats ok ;-)
<FromGitter>
<jwoertink> Ok, so I would write my custom c lib with my `.c` and `.h` files, then use a compiler like `gcc` to make a `.so` or a `.a` file maybe called `libcoolguy.so`. Place that in to /usr/lib or whatever, and then in crystal I could do `@[Link("coolguy")]`?
<BlaXpirit>
jwoertink, yeah but don't actually litter your system like that
<Papierkorb>
jwoertink, the takeaway should be also that linking is a language agnostic concept. Almost any (citation needed) language, which compiles to native machine code, can output object files (or does so behind the scenes), and thus requires a linker. Even if you'd write assembler, you'd use the assembler to *assemble* (an assembler assembles, it doesn't compile ;) ) an object file out of the assembler code, which you'd then link. You can, in
<Papierkorb>
theory at least, even mix object files from different languages into a big program
<BlaXpirit>
you can put the .so file anywhere and add it to {LD_,}LIBRARY_PATH=/full/path/to/libcoolguy.so
<FromGitter>
<jwoertink> This syntax ` {LD_,}LIBRARY_PATH=/full/path/to/libcoolguy.so` is like something I'd put in a .bashrc?
<FromGitter>
<jwoertink> or that's what I would pass to the compiler during compilation?
<Papierkorb>
jwoertink, simplest and best solution while developing the shard/lib is to use LD_LIBRARY_PATH. if your libcoolguy.so resides in ext/lib, which your crystal program links against, you'd type: LD_LIBRARY_PATH=ext/lib crystal run my_script.cr
<FromGitter>
<jwoertink> ah!
pawnbox has joined #crystal-lang
<FromGitter>
<jwoertink> :bulb:
<Papierkorb>
jwoertink, that is, on a single line, to run the script. You can also write "export LD_LIBRARY_PATH=..." once and then just use `crystal` like normal. This way, you only change the current shell session, and not everything, but you also have a (maybe) more readable run line ;)
balduin has joined #crystal-lang
<FromGitter>
<jwoertink> Are there docs that show all this stuff in https://crystal-lang.org/docs? I'm looking around and not seeing any
<FromGitter>
<jwoertink> That makes so much more sense now. Is it possible to add that in to the program itself? like `ENV["LD_LIBRARY_PATH"] = File.join("ext", "lib")`?
<FromGitter>
<johnjansen> @jwoertink there are not
<FromGitter>
<jwoertink> I think this is one of the coolest features of crystal
<FromGitter>
<jwoertink> I would love to add Ogre3D in to a shard
<Papierkorb>
jwoertink, No that won't work. The linking happens right before crystal itself is run. Your operating system kernel has a loader which reads the binary (crystal in this case), sees it requires yourlib.so, tries to find it, links it in dynamically, and then starts crystal
<Papierkorb>
jwoertink, so at the time your code is run, the linking already happened and your line doesn't help anymore
<FromGitter>
<jwoertink> oh, ok. I appreciate the explanation!
<FromGitter>
<jwoertink> It makes things so much clearer. Even for the fact of just reading someone else's code and actually understanding what it's doing
<Papierkorb>
Hehe, Ogre3D would be amazing. But leave that one for later, C++ libraries are a whole different matter. I could explain why, but to make it short, use pure C libs for now
<FromGitter>
<jwoertink> lol
<FromGitter>
<jwoertink> Yeah, I'll start small for sure
<FromGitter>
<johnjansen> @jwoertink how about writing up the process as you go
<FromGitter>
<jwoertink> For sure
<FromGitter>
<johnjansen> what are you intending writing
<Papierkorb>
jwoertink, here's a HOWTO on that stuff from a usage and some technical perspective: http://www.dwheeler.com/program-library/Program-Library-HOWTO/t1.html Do note however that most of these documents are bound to be C centric. Not expecting you to read that novel right now though ;)
soveran has quit [Remote host closed the connection]
<FromGitter>
<jwoertink> oh cool. That helps
<FromGitter>
<jwoertink> Not sure what I'll write up. I need to get the hang of C a little bit. Whatever it ends up being, I'll write up some docs on it
<FromGitter>
<johnjansen> my guess is that you will quickly wonder why you are writing in C when crystal is so expressive and well frictionless
<FromGitter>
<jwoertink> hahah. I'm sure.
<Papierkorb>
jwoertink, just a friendly note before you learn C: C has its use-cases, still has today and will have tomorrow, but you may not have one of these :)
<FromGitter>
<johnjansen> @Papierkorb ;-) +1
<FromGitter>
<jwoertink> Agreed. My only real motivation at this point is Ogre lol
<Papierkorb>
jwoertink, looks like there are bindings to Ogre3D from other languages. You may want to look at them too. Still, that will be a big task overall
<FromGitter>
<jwoertink> Yeah, Ogrerb was something I was playing with a long time ago. The project died, which led me to using JRuby with JMonkeyEngine. That was super simple to get up and running.
matp has quit [Excess Flood]
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
balduin has quit [Ping timeout: 256 seconds]
<BlaXpirit>
damn, i probably have a lot to say on C bindings, but i have no idea how to formulate my thoughts in a systematic manner
<FromGitter>
<jwoertink> lol
<FromGitter>
<jwoertink> write them on magnets, then throw them at a fridge and take a picture
<Papierkorb>
the picture should be at a slight angle for maximum hipsterness
soveran has quit [Remote host closed the connection]
<FromGitter>
<jwoertink> :joy: exactly
matp has joined #crystal-lang
matp has quit [Ping timeout: 250 seconds]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
pawnbox has quit [Remote host closed the connection]
soveran has quit [Remote host closed the connection]
kochev has quit [Remote host closed the connection]
HakanD__ has quit [Quit: Be back later ...]
HakanD__ has joined #crystal-lang
HakanD__ has quit [Ping timeout: 244 seconds]
matp has joined #crystal-lang
HakanD__ has joined #crystal-lang
optikfluffel has joined #crystal-lang
soveran has joined #crystal-lang
HakanD__ has quit [Quit: Be back later ...]
HakanD__ has joined #crystal-lang
<crystal-gh>
[crystal] ggiraldez opened pull request #3473: Emit debug information for toplevel variables (master...debug/toplevel-vars) https://git.io/vPjs5
HakanD__ has quit [Ping timeout: 245 seconds]
bjz has joined #crystal-lang
gloscombe has quit [Remote host closed the connection]
optikfluffel has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
optikfluffel has joined #crystal-lang
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 244 seconds]
HakanD__ has joined #crystal-lang
optikfluffel has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
soveran has quit [Remote host closed the connection]
HakanD__ has quit [Quit: Be back later ...]
HakanD__ has joined #crystal-lang
HakanD__ has quit [Ping timeout: 256 seconds]
zvrk has joined #crystal-lang
bjz has joined #crystal-lang
optikfluffel has joined #crystal-lang
zvrk has quit [Quit: Page closed]
onethirtyfive has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
optikfluffel has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
optikfluffel has joined #crystal-lang
optikfluffel has quit [Client Quit]
optikfluffel has joined #crystal-lang
optikfluffel has quit [Client Quit]
optikfluffel has joined #crystal-lang
optikfluffel has quit [Client Quit]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
bjz has quit [Ping timeout: 256 seconds]
optikfluffel has joined #crystal-lang
optikfluffel has quit [Client Quit]
optikfluffel has joined #crystal-lang
optikfluffel has quit [Client Quit]
soveran has quit [Ping timeout: 260 seconds]
onethirtyfive has quit [Remote host closed the connection]