-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to compile a static library (libmpv.a) #7738
Comments
As far as I know, the linker here is yelling at you correctly. If you're linking the static library into a shared object, you need position independent code. |
So CFLAGS with the module? Or in MPV? From what I interpret you mean it should be at the module side but that doesn't seem to be doing anything. I might be doing something wrong though, so I'll keep looking into it. Incase it's the other side, where exactly do I add the CFLAGS in MPV? I tried |
Yeah I even put it in LDFlags just in case, still not working. You will see duplicates of this switch in the verbose output below, that was me testing things. Still same error (from the module side):
|
the mpv build needs to have -fPIC enabled, not just FFmpeg and not the LDFLAGS. though I'm not sure if there isn't some other smarter way to go about what you're trying to do (making a dynamic lib from a static lib seems a bit weird) |
How do I add the flag to mpv? As I mentioned in the comment above I only figured how to do it for the ffmpeg side. I don't want to manually edit the wrong files since this process seems very intertwined. I did just try appending it to the wscript_build.py under (Also yeah I know about the LDFLAGS, I just did it since it didn't seem to change anything when I added CFLAGS, besides it wasn't working anyway so may as well try it temporarily. The worst case it fails to compile anyway but with a different error.) |
Usually by setting a
(the CFLAGS should stick during the build step, as the configure step picked them up) |
Thanks for your input in all of this! Really appreciate it. When I ran the first command there were a few reds but the one at the bottom seems a bit concerning:
Either way, didn't change the result sadly |
I want to add the generated build/libmpv.a has always been around 16.3 MB. In case the size might give some hints. |
The -fPIC warning is because all code linked to a shared lib, or a PIE executable, must be built with PIC. So you need to add -fPIC to all libs statically linked to libmpv.a. If the ffmpeg check fails, look at build/config.log. |
@wm4 Ok I'll have a go at that |
This may seem quite useful I think; there are situations where a static library can be useful. For example, I often end up breaking some stuff on my system and I need mpv to play good music so I am motivated to fix anything. :D |
Linking a static library to a shared one is not difficult - you can just run |
I am getting a ton of undefined references trying to link to libmpv
This is how I'm building it:
And scons:
(By the way, this is on my https://github.com/nathanfranke/gdmpv repo) |
Sounds like it's not linking to libswresample. |
This is one of hundreds of errors, many of which are not libswresample. https://pastebin.com/1HcFDdkR |
Sounds like it's not linking to any library it needs to link to. |
Do you know of a way to fix this? I need to statically link every dependency. |
Looks like libmpv.a contains swresample (There's other linker errors, just using this one as an example)
I get the same errors even if I manually link every other library (which I shouldn't need to do)
(fyi, I also added |
@nathanfranke I have the exact same issue trying to statically link libmpv to a Kotlin/Native application. Undefined references to methods in several ffmpeg dependencies, even when statically linking to those dependencies as well. Dynamic linking works fine. Did you ever find a solution to this issue? Sorry to revive this thread again. Edit: I should note that I'm using v0.35.0 since Kotlin/Native requires static libs to be compiled using an older version of glibc Edit: Fast-forward three months, and I've rediscovered this comment while trying to accomplish this again, this time with v0.38.0 but with the same result. |
Hi all,
I have been trying for quite a while to build a static version of libmpv to be used in a module. For additional information as I was documenting what I was doing you can find out more here: Kagami/mpv.js#68 .
Long story short, after enabling
--enable-libmpv-static
it compiles successfully. But on the other side when trying to link it in a module I get the errors (taken the most important part):libmpv.a(mp_image.c.26.o): relocation R_X86_64_PC32 against symbolmp_image_setfmt' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
This is after linking the libmpv.a in binding.gyp. Full error below:
CXX(target) Release/obj.target/mpvjs/index.o SOLINK_MODULE(target) Release/obj.target/mpvjs.node /usr/bin/ld: /home/extern/Downloads/test/lol/lib-retry/node_modules/mpv.js/mpv-build/mpv/build/libmpv.a(mp_image.c.26.o): relocation R_X86_64_PC32 against symbolmp_image_setfmt' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status mpvjs.target.mk:158: recipe for target 'Release/obj.target/mpvjs.node' failed make: *** [Release/obj.target/mpvjs.node] Error 1 make: Leaving directory '/home/extern/Downloads/test/lol/lib-retry/node_modules/mpv.js/build' gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:194:23) gyp ERR! stack at ChildProcess.emit (events.js:315:20) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) gyp ERR! System Linux 5.3.0-51-generic gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "rebuild" gyp ERR! cwd /home/extern/Downloads/test/lol/lib-retry/node_modules/mpv.js gyp ERR! node -v v13.14.0 gyp ERR! node-gyp -v v6.1.0 gyp ERR! not ok
Thanks
The text was updated successfully, but these errors were encountered: