Skip to content
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

Closed
mcrha opened this issue Feb 6, 2023 · 16 comments · Fixed by #994
Closed

build: Fails to build due to under-linking #267

mcrha opened this issue Feb 6, 2023 · 16 comments · Fixed by #994
Assignees
Labels
Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take

Comments

@mcrha
Copy link
Contributor

mcrha commented Feb 6, 2023

When using stricter options for linking the project fails to build due to undefined symbols. Steps:

   export LDFLAGS='-Wl,--as-needed -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-z -Wl,defs'
   cmake .....
   make

current result is tons of undefined references, beginning with:

/usr/bin/ld: CMakeFiles/actions.dir/actions.cpp.o: in function `(anonymous namespace)::Actions::substitute(libdnf::base::TransactionPackage const*, libdnf::rpm::Package const*, std::basic_string_view<char, std::char_traits<char> >, std::filesystem::__cxx11::path, int)':
..../dnf5/libdnf-plugins/actions/actions.cpp:223: undefined reference to `libdnf::OptionBinds::Item::get_value_string[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:239: undefined reference to `libdnf::rpm::Package::get_name[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:241: undefined reference to `libdnf::rpm::Package::get_arch[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:243: undefined reference to `libdnf::rpm::Package::get_version[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:245: undefined reference to `libdnf::rpm::Package::get_release[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:247: undefined reference to `libdnf::rpm::Package::get_epoch[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:249: undefined reference to `libdnf::rpm::Package::get_na[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:251: undefined reference to `libdnf::rpm::Package::get_evr[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:253: undefined reference to `libdnf::rpm::Package::get_nevra[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:255: undefined reference to `libdnf::rpm::Package::get_full_nevra[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:257: undefined reference to `libdnf::rpm::Package::get_repo_id[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:259: undefined reference to `libdnf::rpm::Package::get_license[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:261: undefined reference to `libdnf::rpm::Package::get_location[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:263: undefined reference to `libdnf::rpm::Package::get_vendor[abi:cxx11]() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:268: undefined reference to `libdnf::transaction::transaction_item_action_to_letter[abi:cxx11](libdnf::transaction::TransactionItemAction)'
/usr/bin/ld: CMakeFiles/actions.dir/actions.cpp.o: in function `(anonymous namespace)::Actions::parse_action_files()':
..../dnf5/libdnf-plugins/actions/actions.cpp:367: undefined reference to `libdnf::ConfigMain::pluginconfpath() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:369: undefined reference to `libdnf::ConfigMain::pluginconfpath() const'
/usr/bin/ld: ..../dnf5/libdnf-plugins/actions/actions.cpp:369: undefined reference to `libdnf::OptionString::get_value[abi:cxx11]() const'

Using only LDFLAGS='-Wl,--as-needed makes it build with no problem.

@jrohel jrohel self-assigned this Feb 6, 2023
@github-project-automation github-project-automation bot moved this to Backlog in DNF team Apr 14, 2023
@j-mracek
Copy link
Contributor

@mcrha May I ask you whether the issue is still valid and whether you consider the issue as critical?

@j-mracek j-mracek added the Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take label Aug 29, 2023
@mcrha
Copy link
Contributor Author

mcrha commented Aug 29, 2023

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.

@ppisar
Copy link
Contributor

ppisar commented Aug 29, 2023

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.

@mcrha
Copy link
Contributor Author

mcrha commented Aug 29, 2023

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.

@ppisar
Copy link
Contributor

ppisar commented Aug 30, 2023

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.

@jrohel
Copy link
Contributor

jrohel commented Aug 30, 2023

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"?

@mcrha
Copy link
Contributor Author

mcrha commented Aug 30, 2023

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.

@jrohel
Copy link
Contributor

jrohel commented Aug 30, 2023

  1. I agree that for example "dnf5-plugins/changelog_plugin" should link to "libdnf5" (since it uses it directly internally) and not rely on the dnf5 application to load it.

  2. But link the dnf5 application? dnf5 will definitely be in the environment, because it is the one that loads the plugin. And using target_link_libraries to link the plugin with dnf5 will check that dnf5 has ENABLE_EXPORTS enabled. Good thing too. I will add. But linking on the ELF platform will not happen.

  3. But I'm still not sure if we want to split the dnf5 application into a library and a small wrapper using it. After all, plugins are loadable MODULES. And they use ENABLE_EXPORTS which is intended for that. https://cmake.org/cmake/help/v3.14/prop_tgt/ENABLE_EXPORTS.html

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.

@mcrha
Copy link
Contributor Author

mcrha commented Aug 30, 2023

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:

#include <libdnf5/base/base.hpp>
#include <libdnf5/base/transaction.hpp>
#include <libdnf5/common/exception.hpp>
#include <libdnf5/rpm/package_query.hpp>
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>

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.

@jrohel
Copy link
Contributor

jrohel commented Aug 30, 2023

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.
The "dnf5-plugins" directory contains the dnf5 application plugins. So they are loaded by the dnf5 application.
The "libdnf5-plugins" directory contains the libdnf5 library plugins. So they are loaded by the libdnf5 library. These plugins have no relation to the dnf5 application. Action plugin is a plugin of the libdnf5 library. It doesn't use anything from the dnf5 app.

@jrohel
Copy link
Contributor

jrohel commented Aug 31, 2023

I prepared a second PR #853 that tune library linking.
With my two PRs, compiling with LDFLAGS='-Wl,--as-needed -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-z -Wl,defs' fails only for dnf5 plugins.

@jrohel jrohel moved this from Backlog to In Progress in DNF team Sep 27, 2023
@j-mracek
Copy link
Contributor

@jrohel @mcrha May I ask you a question? Do you consider the issue as resolved?

@mcrha
Copy link
Contributor Author

mcrha commented Oct 18, 2023

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.

@ppisar
Copy link
Contributor

ppisar commented Nov 3, 2023

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.

@jrohel
Copy link
Contributor

jrohel commented Nov 3, 2023

Note on dnf5 application plugins:
Dependency on the dnf5 application is listed in the CMakeLists.txt files. So the build process knows about it. This also enforces that ENABLE_EXPORTS must be set for the dnf5 application. And dnf5 symbols are exported.
Dnf5 application plugins are loaded by dnf5 application, thus dnf5 application is in memory. And dynamic loader will automatically bind symbols when the module is loaded.

The problem looks more like an artificial problem created by inappropriate linker settings for application plugins.
For platforms where this is really necessary, cmake should automatically generate the necessary interlibrary.

@mcrha wrote that he has a workaround. I prefer to close this issue.

@ppisar ppisar self-assigned this Nov 3, 2023
ppisar added a commit to ppisar/dnf5 that referenced this issue Nov 3, 2023
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>.
ppisar added a commit to ppisar/dnf5 that referenced this issue Nov 3, 2023
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
@ppisar ppisar linked a pull request Nov 3, 2023 that will close this issue
@ppisar
Copy link
Contributor

ppisar commented Nov 3, 2023

I posted #994 PR which should resolve this issue.

ppisar added a commit to ppisar/dnf5 that referenced this issue Nov 3, 2023
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>.
ppisar added a commit to ppisar/dnf5 that referenced this issue Nov 3, 2023
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
ppisar added a commit to ppisar/dnf5 that referenced this issue Nov 3, 2023
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>.
ppisar added a commit to ppisar/dnf5 that referenced this issue Nov 3, 2023
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
github-merge-queue bot pushed a commit that referenced this issue Nov 6, 2023
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>.
github-merge-queue bot pushed a commit that referenced this issue Nov 6, 2023
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
@github-project-automation github-project-automation bot moved this from In Progress to Done in DNF team Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants