Thank you for the clarification!
So now I am running into another issue maybe you know the answer to: once I have built my executable, I run into a
dyld: Library not loaded error when trying to run the executable.
My project is set up like this:
│ ├── executable
│ │ ├── hola
│ │ └── liblib.dylib
│ └── lib
│ ├── lib.swiftdoc
│ ├── lib.swiftmodule
│ └── liblib.dylib
│ └── main.swift
And I am building the library and executable with these commands respectively:
$ cd build/lib
$ swiftc -emit-module -emit-library ../../lib/lib.swift
$ cd build/executable
$ swiftc -I../lib -L../lib -llib ../../executable/main.swift -o ./main
The complete error is this:
dyld: Library not loaded: liblib.dylib
Referenced from: path/to/build/executable/main
Reason: image not found
Abort trap: 6
So if I understand, the problem is that the executable cannot be linked with the dylib at runtime.
Interestingly, if I run the executable from the directory where
liblib.dylib is located, it works perfectly.
So the question is, how do I correctly specify the path to the dynamic library for the executable to find it at runtime? I would have thought the
-L argument would specify this.