-
Notifications
You must be signed in to change notification settings - Fork 86
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
build: Fails to build due to under-linking #267
Comments
@mcrha May I ask you whether the issue is still valid and whether you consider the issue as critical? |
Yes, it is still reproducible on the main branch at commit bf87232 . How much critical, well, it's up to you to decide. It's not an ideal state, but I know the workaround, thus no big deal from my side. |
Is it triggered with "-Wl,-z -Wl,defs"? The other linker flags are used in ELN build regularly. Frankly, after reading -z defs documentation in ld(1) manual, I don't understand what it is good for. From the error message, I would guess a plugin, technically a shared library, is either not linked to libdnf5, or the plugin includes header files with private symbols. However, according to the manual -z defs pertain non-shared library objects. |
The flags are used by some distros/build environments to ensure the objects link to all the libraries they use. It helps to avoid "symbol not found" in the runtime, if I recall correctly. |
Now I understand the option. By default GNU linker behaves differently when linking programs and when linking libraries. -z defs and -z undefs enforce uniform behavior either that or another way. |
I've created a PR #848 that fixes missing linkage in swig generated libraries. But "actions.cpp", more precisely everything in the "libdnf5-plugins" and "dnf5-plugins" directories are plugins. I'm not sure how to solve it with them yet. And is it correct to compile the plugins with "-Wl,-z -Wl,defs"? |
I do not think the LDFLAGS variable can be selectively applied, not without changes in the build scripts, but those might be wrong (removing distro-specified flags, which should be left there). As long as the plugins use public API (headers), that API should contains also public libraries, thus the plugins should link against those libraries, instead of expecting the plugin is loaded into an environment, where all the public API libraries are already loaded in the process. That's my understanding of the matter. I can be wrong. |
I think the first PR #848 is OK. I will prepare a follow-up PR. According to points 1 and 2. But I will not yet change the application to a library with a "wrapper", which will turn it into an application. |
Linking library (module) against executable (or another module) is not a thing one should do, let aside it won't work (from my point of view). Some projects have it as you suggested, split the "API" into a linkable library and have the application code load/link against that library too, thus make the app code work like a wrapper. It adds certain complexity in the code maintenance for sure. The "only" advantage of this approach is a clean linker tree within the code. If it feels as an unnecessary overhead for the dnf5 use case, then feel free to not doing that. By the way, the https://github.com/rpm-software-management/dnf5/blob/main/libdnf5-plugins/actions/actions.cpp seems to include these internal headers:
are any/all of them considered "an application" code? I do not know the code structure of the dnf, I'm sorry if it's a lame question. |
It's more complicated. There are 2 types of plugins in the dnf5 project. |
I prepared a second PR #853 that tune library linking. |
I tried with the main branch at commit 8b515b7 and it still fails when linking changelog_cmd_plugin.so, builddep_cmd_plugin.so and copr_cmd_plugin.so (the build stopped with these three), which reflects the last Jaroslav comment (about "only plugins fail now). That being said, the situation is better, but not fixed. If you want to, then feel free to close this (even proper linking flags would be better). I know how to workaround the problem. |
changelog_cmd_plugin, builddep_cmd_plugin, and copr_cmd_plugin are plugins into dnf5 program which call symbols for the program. "-z defs" cannot work for such plugins. We could nullify LDFLAGS "-z defs" effect by appending "-z undefs" to linker flags for these specific dnf5 program plugins, but I'm not sure it's worth of working around unreasonable distribution global LDFLAGS. I will look whether it's possible, if it is, I will create a pull request, otherwise I will reject this bug report. |
Note on dnf5 application plugins: The problem looks more like an artificial problem created by inappropriate linker settings for application plugins. @mcrha wrote that he has a workaround. I prefer to close this issue. |
Building with LDFLAGS='-Wl,-z,defs' shows among others: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols [...] /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:125:(.text+0xba8): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:127:(.text+0xbba): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:126:(.text+0xbe1): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:129:(.text+0xbf6): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:130:(.text+0xc0f): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:132:(.text+0xc21): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:131:(.text+0xc48): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:134:(.text+0xc5d): undefined reference to `rpmdsFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::add_from_srpm_file(std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, char const*)': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:141:(.text+0xc9f): undefined reference to `Fopen' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:142:(.text+0xcb6): undefined reference to `Ferror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:143:(.text+0xd1d): undefined reference to `Fstrerror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:145:(.text+0xd4d): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:152:(.text+0xd64): undefined reference to `rpmtsCreate' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:153:(.text+0xd79): undefined reference to `rpmtsSetVSFlags' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:154:(.text+0xd95): undefined reference to `rpmReadPackageFile' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:155:(.text+0xda4): undefined reference to `rpmtsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:156:(.text+0xdb0): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xddd): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xde5): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:162:(.text+0xdf7): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:161:(.text+0xe46): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:167:(.text+0xe5b): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe76): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe7e): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:170:(.text+0xe90): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:169:(.text+0xeb7): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:172:(.text+0xecc): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:177:(.text+0xf2c): undefined reference to `headerFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:223:(.text+0x1966): undefined reference to `rpmPushMacro' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:231:(.text+0x1aae): undefined reference to `rpmPopMacro' All these functions are explicitly called from builddep.cpp, hence builddep.cpp must include header files defining the functions and must link to libraries providing them. rpmbuild header and library were utilizied. But librpm and librpmio were completely missing. This patch adds them. Related to <rpm-software-management#267>.
dnf5-plugins are plugins which use symbols from dnf5 program. On ELF platforms, these symbols remain unresolved at compilation time. GNU linker knows that and thus does not enforce -z defs semantics by default. Yet some overzeleous distributions or devolopers use -z defs linker flags to quality-check for an underlinking and then the build fails like this: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so -lrpm -lrpmio -lpopt ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()::{lambda(char const*)rpm-software-management#1}::operator()(char const*) const': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:62:(.text+0x104): undefined reference to `dnf5::match_specs(dnf5::Context&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool, bool, bool, char const*)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:68:(.text+0x5e7): undefined reference to `dnf5::create_allow_downgrade_options(dnf5::Command&)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:258:(.text+0x1d1d): undefined reference to `dnf5::Context::get_goal(bool)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::Command::~Command()': /home/test/dnf5/dnf5/include/dnf5/context.hpp:164:(.text._ZN4dnf57CommandD2Ev[_ZN4dnf57CommandD5Ev]+0xf): undefined reference to `vtable for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o:(.data.rel.ro._ZTIN4dnf515BuildDepCommandE[_ZTIN4dnf515BuildDepCommandE]+0x10): undefined reference to `typeinfo for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o: in function `dnf5::Command::Command(libdnf5::cli::session::Session&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/test/dnf5/dnf5/include/dnf5/context.hpp:166:(.text._ZN4dnf57CommandCI2N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN4dnf57CommandCI5N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2e): undefined reference to `vtable for dnf5::Command' collect2: error: ld returned 1 exit status This patch works around it by appending -z undefs when linking dnf5 program plugins. Implementation detail: target_link_options() as well as other CMake functions place their values before system-wide flags inherited from an envirnoment. Therefore this patch simply modifies CMAKE_MODULE_LINKER_FLAGS CMake variable. Resolves: rpm-software-management#267
I posted #994 PR which should resolve this issue. |
Building with LDFLAGS='-Wl,-z,defs' shows among others: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols [...] /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:125:(.text+0xba8): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:127:(.text+0xbba): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:126:(.text+0xbe1): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:129:(.text+0xbf6): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:130:(.text+0xc0f): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:132:(.text+0xc21): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:131:(.text+0xc48): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:134:(.text+0xc5d): undefined reference to `rpmdsFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::add_from_srpm_file(std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, char const*)': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:141:(.text+0xc9f): undefined reference to `Fopen' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:142:(.text+0xcb6): undefined reference to `Ferror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:143:(.text+0xd1d): undefined reference to `Fstrerror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:145:(.text+0xd4d): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:152:(.text+0xd64): undefined reference to `rpmtsCreate' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:153:(.text+0xd79): undefined reference to `rpmtsSetVSFlags' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:154:(.text+0xd95): undefined reference to `rpmReadPackageFile' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:155:(.text+0xda4): undefined reference to `rpmtsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:156:(.text+0xdb0): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xddd): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xde5): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:162:(.text+0xdf7): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:161:(.text+0xe46): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:167:(.text+0xe5b): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe76): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe7e): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:170:(.text+0xe90): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:169:(.text+0xeb7): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:172:(.text+0xecc): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:177:(.text+0xf2c): undefined reference to `headerFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:223:(.text+0x1966): undefined reference to `rpmPushMacro' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:231:(.text+0x1aae): undefined reference to `rpmPopMacro' All these functions are explicitly called from builddep.cpp, hence builddep.cpp must include header files defining the functions and must link to libraries providing them. rpmbuild header and library were utilizied. But librpm and librpmio were completely missing. This patch adds them. Related to <rpm-software-management#267>.
dnf5-plugins are plugins which use symbols from dnf5 program. On ELF platforms, these symbols remain unresolved at compilation time. GNU linker knows that and thus does not enforce -z defs semantics by default. Yet some overzeleous distributions or devolopers use -z defs linker flags to quality-check for an underlinking and then the build fails like this: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so -lrpm -lrpmio -lpopt ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()::{lambda(char const*)rpm-software-management#1}::operator()(char const*) const': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:62:(.text+0x104): undefined reference to `dnf5::match_specs(dnf5::Context&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool, bool, bool, char const*)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:68:(.text+0x5e7): undefined reference to `dnf5::create_allow_downgrade_options(dnf5::Command&)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:258:(.text+0x1d1d): undefined reference to `dnf5::Context::get_goal(bool)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::Command::~Command()': /home/test/dnf5/dnf5/include/dnf5/context.hpp:164:(.text._ZN4dnf57CommandD2Ev[_ZN4dnf57CommandD5Ev]+0xf): undefined reference to `vtable for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o:(.data.rel.ro._ZTIN4dnf515BuildDepCommandE[_ZTIN4dnf515BuildDepCommandE]+0x10): undefined reference to `typeinfo for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o: in function `dnf5::Command::Command(libdnf5::cli::session::Session&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/test/dnf5/dnf5/include/dnf5/context.hpp:166:(.text._ZN4dnf57CommandCI2N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN4dnf57CommandCI5N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2e): undefined reference to `vtable for dnf5::Command' collect2: error: ld returned 1 exit status This patch works around it by appending -z undefs when linking dnf5 program plugins. Implementation detail: target_link_options() as well as other CMake functions place their values before system-wide flags inherited from an envirnoment. Therefore this patch simply modifies CMAKE_MODULE_LINKER_FLAGS CMake variable. Resolves: rpm-software-management#267
Building with LDFLAGS='-Wl,-z,defs' shows among others: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols [...] /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:125:(.text+0xba8): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:127:(.text+0xbba): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:126:(.text+0xbe1): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:129:(.text+0xbf6): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:130:(.text+0xc0f): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:132:(.text+0xc21): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:131:(.text+0xc48): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:134:(.text+0xc5d): undefined reference to `rpmdsFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::add_from_srpm_file(std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, char const*)': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:141:(.text+0xc9f): undefined reference to `Fopen' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:142:(.text+0xcb6): undefined reference to `Ferror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:143:(.text+0xd1d): undefined reference to `Fstrerror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:145:(.text+0xd4d): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:152:(.text+0xd64): undefined reference to `rpmtsCreate' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:153:(.text+0xd79): undefined reference to `rpmtsSetVSFlags' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:154:(.text+0xd95): undefined reference to `rpmReadPackageFile' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:155:(.text+0xda4): undefined reference to `rpmtsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:156:(.text+0xdb0): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xddd): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xde5): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:162:(.text+0xdf7): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:161:(.text+0xe46): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:167:(.text+0xe5b): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe76): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe7e): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:170:(.text+0xe90): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:169:(.text+0xeb7): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:172:(.text+0xecc): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:177:(.text+0xf2c): undefined reference to `headerFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:223:(.text+0x1966): undefined reference to `rpmPushMacro' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:231:(.text+0x1aae): undefined reference to `rpmPopMacro' All these functions are explicitly called from builddep.cpp, hence builddep.cpp must include header files defining the functions and must link to libraries providing them. rpmbuild header and library were utilizied. But librpm and librpmio were completely missing. This patch adds them. Related to <rpm-software-management#267>.
dnf5-plugins are plugins which use symbols from dnf5 program. On ELF platforms, these symbols remain unresolved at compilation time. GNU linker knows that and thus does not enforce -z defs semantics by default. Yet some overzeleous distributions or devolopers use -z defs linker flags to quality-check for an underlinking and then the build fails like this: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so -lrpm -lrpmio -lpopt ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()::{lambda(char const*)rpm-software-management#1}::operator()(char const*) const': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:62:(.text+0x104): undefined reference to `dnf5::match_specs(dnf5::Context&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool, bool, bool, char const*)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:68:(.text+0x5e7): undefined reference to `dnf5::create_allow_downgrade_options(dnf5::Command&)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:258:(.text+0x1d1d): undefined reference to `dnf5::Context::get_goal(bool)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::Command::~Command()': /home/test/dnf5/dnf5/include/dnf5/context.hpp:164:(.text._ZN4dnf57CommandD2Ev[_ZN4dnf57CommandD5Ev]+0xf): undefined reference to `vtable for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o:(.data.rel.ro._ZTIN4dnf515BuildDepCommandE[_ZTIN4dnf515BuildDepCommandE]+0x10): undefined reference to `typeinfo for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o: in function `dnf5::Command::Command(libdnf5::cli::session::Session&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/test/dnf5/dnf5/include/dnf5/context.hpp:166:(.text._ZN4dnf57CommandCI2N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN4dnf57CommandCI5N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2e): undefined reference to `vtable for dnf5::Command' collect2: error: ld returned 1 exit status This patch works around it by appending -z undefs when linking dnf5 program plugins. Implementation detail: target_link_options() as well as other CMake functions place their values before system-wide flags inherited from an envirnoment. Therefore this patch simply modifies CMAKE_MODULE_LINKER_FLAGS CMake variable. Resolves: rpm-software-management#267
Building with LDFLAGS='-Wl,-z,defs' shows among others: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols [...] /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:125:(.text+0xba8): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:127:(.text+0xbba): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:126:(.text+0xbe1): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:129:(.text+0xbf6): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:130:(.text+0xc0f): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:132:(.text+0xc21): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:131:(.text+0xc48): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:134:(.text+0xc5d): undefined reference to `rpmdsFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::add_from_srpm_file(std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, char const*)': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:141:(.text+0xc9f): undefined reference to `Fopen' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:142:(.text+0xcb6): undefined reference to `Ferror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:143:(.text+0xd1d): undefined reference to `Fstrerror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:145:(.text+0xd4d): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:152:(.text+0xd64): undefined reference to `rpmtsCreate' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:153:(.text+0xd79): undefined reference to `rpmtsSetVSFlags' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:154:(.text+0xd95): undefined reference to `rpmReadPackageFile' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:155:(.text+0xda4): undefined reference to `rpmtsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:156:(.text+0xdb0): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xddd): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xde5): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:162:(.text+0xdf7): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:161:(.text+0xe46): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:167:(.text+0xe5b): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe76): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe7e): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:170:(.text+0xe90): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:169:(.text+0xeb7): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:172:(.text+0xecc): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:177:(.text+0xf2c): undefined reference to `headerFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:223:(.text+0x1966): undefined reference to `rpmPushMacro' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:231:(.text+0x1aae): undefined reference to `rpmPopMacro' All these functions are explicitly called from builddep.cpp, hence builddep.cpp must include header files defining the functions and must link to libraries providing them. rpmbuild header and library were utilizied. But librpm and librpmio were completely missing. This patch adds them. Related to <#267>.
dnf5-plugins are plugins which use symbols from dnf5 program. On ELF platforms, these symbols remain unresolved at compilation time. GNU linker knows that and thus does not enforce -z defs semantics by default. Yet some overzeleous distributions or devolopers use -z defs linker flags to quality-check for an underlinking and then the build fails like this: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so -lrpm -lrpmio -lpopt ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()::{lambda(char const*)#1}::operator()(char const*) const': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:62:(.text+0x104): undefined reference to `dnf5::match_specs(dnf5::Context&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool, bool, bool, char const*)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:68:(.text+0x5e7): undefined reference to `dnf5::create_allow_downgrade_options(dnf5::Command&)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:258:(.text+0x1d1d): undefined reference to `dnf5::Context::get_goal(bool)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::Command::~Command()': /home/test/dnf5/dnf5/include/dnf5/context.hpp:164:(.text._ZN4dnf57CommandD2Ev[_ZN4dnf57CommandD5Ev]+0xf): undefined reference to `vtable for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o:(.data.rel.ro._ZTIN4dnf515BuildDepCommandE[_ZTIN4dnf515BuildDepCommandE]+0x10): undefined reference to `typeinfo for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o: in function `dnf5::Command::Command(libdnf5::cli::session::Session&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/test/dnf5/dnf5/include/dnf5/context.hpp:166:(.text._ZN4dnf57CommandCI2N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN4dnf57CommandCI5N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2e): undefined reference to `vtable for dnf5::Command' collect2: error: ld returned 1 exit status This patch works around it by appending -z undefs when linking dnf5 program plugins. Implementation detail: target_link_options() as well as other CMake functions place their values before system-wide flags inherited from an envirnoment. Therefore this patch simply modifies CMAKE_MODULE_LINKER_FLAGS CMake variable. Resolves: #267
When using stricter options for linking the project fails to build due to undefined symbols. Steps:
current result is tons of undefined references, beginning with:
Using only
LDFLAGS='-Wl,--as-needed
makes it build with no problem.The text was updated successfully, but these errors were encountered: