Improvements and explanations in dynlib example - #7620
Conversation
| @@ -1,4 +1,4 @@ | |||
| package example | |||
| package library | |||
There was a problem hiding this comment.
This change is unnecessary, and actually confuses things as example.odin isn't a library or part of the same package as lib.odin, it is the example that loads said library. And -file means that the different package names in the same directory don't clash, as each file is considered its own package.
It works just fine if you build lib.odin with -file followed by example.odin also using -file.
This is what I have in my build.bat (not in the repo):
odin build lib.odin -file -build-mode:dll -vet
odin run example.odin -file -vetThere was a problem hiding this comment.
My suggestion is to revert the changes to both files, and instead add a doc.odin file. Something along these lines.
/*
This directory comprises two distinct packages:
- `lib.odin` is dynamic library exporting a number of symbols.
- `example.odin` is a separate package, demonstrating how to dynamically load the symbols in `lib.odin`.
To try this out, first compile `lib.odin`, like so:
- `odin build lib.odin -file -build-mode:dll`
Then build and run the example package:
- `odin run example.odin -file`.
If everything goes well, you should see output resembling the following (the addresses may differ):
(Initial DLL Load) ok: true. 3 symbols loaded from lib.dll (0x7FFB3DD90000).
42 + 42 = 84
84 - 13 = 71
hellope = 42
(DLL Reload) ok: true. 3 symbols loaded from lib.dll (0x7FFB3DD90000).
42 + 42 = 84
84 - 13 = 71
hellope = 42
*/
package dynlib_example_documentationThere was a problem hiding this comment.
Oh that's interesting! I wish I knew that!
Your idea seems fine to me. I'll push the PR.
On the side note.
It's not the first time that I run into friction due to not understanding how packages work.
While trying to run raylib
https://github.com/odin-lang/examples/tree/master/raylib/ports/textures
I bulk renamed all the files in folder (except one) from .odin -> odin.off as a workaround to compilation errors.
Only now I've found an explanation in
https://github.com/odin-lang/examples/blob/master/raylib/ports/README.md
Maybe this behaviour could be mentioned in https://odin-lang.org/docs/overview/#packages ?
It does not suggest anything about compiling single file.

There was a problem hiding this comment.
Hmmm..
So this is explained in the docs after all. I'm not sure how to explain this better.
Few thoughts: when I've run into I was just thinking: "how do I get rid of this compilation error?"*
- There are two types of these that I've run into:
- about conflicting package names:
EXAMPLES_ROOT/raylib/ports/textures/textures_gif_player.odin(1:1) Syntax Error: Different package name, expected 'raylib_examples', got 'main'
- about duplicate main() procedures:
[...]
EXAMPLES_ROOT/raylib/ports/textures/textures_npatch_drawing.odin(27:1) Error: Redeclaration of 'main' in this scope
at EXAMPLES_ROOT/raylib/ports/textures/textures_background_scrolling.odin(23:1)
main :: proc() {
^
EXAMPLES_ROOT/raylib/ports/textures/textures_bunnymark.odin(32:1) Error: Redeclaration of the entry pointer procedure 'main'
main :: proc() {
^
[...]
Two suggestions that come to my mind are:
- Move the paragraph you mentioned to the bottom "packages" section. Hopefully this way one will have better understanding of the subject matter to appreciate that paragraph.
- Make the two error messages more verbose. Add the suggestion about single file compilation?
There was a problem hiding this comment.
I already added mention of -file under the Packages header.
There was a problem hiding this comment.
Hinting at -file in the compilation errors is a good shout.
|
I've pushed the changes you suggested |


While learning how to load a *.dll I studied
\ODIN\core\dynlib\example\example.odinI've run into two small issues while trying to run the example:
I hope this PR helps with these two.