Avoid add_constraint symbol conflict.#60
Open
kkofler wants to merge 1 commit intodarnstrom:masterfrom
Open
Conversation
include/auxiliary.h (remove_constraint, add_constraint): Use #define to rename these to less generic names (daqp_aux_remove_constraint and daqp_aux_add_constraint), to work around a symbol conflict with other solvers (in particular, with lp_solve).
This was referenced Nov 22, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
include/auxiliary.h (remove_constraint, add_constraint): Use #define to rename these to less generic names (daqp_aux_remove_constraint and daqp_aux_add_constraint), to work around a symbol conflict with other solvers (in particular, with lp_solve).
This is a fun one I had to debug. In my application, I have to solve both LPs and NLPs. For the LPs, I am currently using lp_solve. For the NLPs, I am using SLSQP, and trying DAQP for the QPs in SLSQP.
Unfortunately, lp_solve has a public API symbol called
add_constraint, which, as a result, is also exported from the shared library. This is bad, but I doubt I can get lp_solve fixed. As a result, we ended up with a symbol conflict, and (only in that executable linked to both lp_solve and DAQP) DAQP code was calling the lp_solveadd_constraintinstead of the DAQP one fromauxiliary.c. (Unfortunately, the glibcld.sowill just silently resolve all references to a given symbol name to the first symbol with that name that it sees, even when that is clearly not what we want.) Obviously, this caused DAQP to fail.add_constraintandremove_constraintare really generic names that are just asking for symbol confllicts. My application actually ends up with 3 differentadd_constraintfunctions linked in, since there is also one in NLOPT, however the NLOPT one isstaticto a single C file and as such not visible externally, hence it does not participate in symbol conflicts.There are 2 things that can be done to prevent this kind of conflicts:
__attribute__((visibility("hidden"))), or use-fvisibility=hiddenand add__attribute__((visibility("default")))for the symbols that should be exported). Note that this means that DAQP shared libraries no longer export those symbols (those that have hidden rather than default visibility), so those functions cannot be called directly anymore, if that is something you want to support.auxiliary.hfrom DAQP before lp_solve headers, the#definehack will break).