I know it’s not common to do like this, but my struct must stay intact in the generated elf file, as it’s a pluginformat, and it uses metadata in the .so file so files can be scanned without running code in them.
Welcome to Odin. Not sure if I’m interpretting what I see correctly, but there are some syntax errors (the quotes) in the provided code, plus, .h files I do not believe can be imported.
Message from compiler:
With ‘foreign import’, you cannot import a .h file/directory, you must precompile the library and link against that
So with that, I think it would look more like:
foreign import C {
// static lib in linux
"plugin_api.a",
// shared lib in linux
"plugin_api.so",
// static/import library in windows
"plugin_api.lib",
}
foreign import in Odin is for defining a procedure interface for foreign functions. Any structs that those foreign functions expect would need to be defined in Odin with the correct signatures to work.
How do you make a struct visible as a global symbol in a object file?
In Odin, define the struct as a global constant:
// Constant struct variable, cannot be reused
MyStruct :: struct {
var1: cstring,
var2: cstring,
}{
var1 = "stuff 01",
var2 = "stuff 02",
}
// or
// struct definition, can be reused for other variables
MyStruct :: struct {
var1: cstring,
var2: cstring,
}
// variable defined using struct definition
mystruct :: MyStruct {
var1 = "stuff 01",
var2 = "stuff 02",
}