Simplify symbol export

Currently, the logic for exporting symbols is rather complicated: when
tests are enabled internal symbols are exported in addition to the
public symbols. Such logic causes several problems. (1) Test binaries
link against a Ceres build that is different from the final release
since fewer optimizations are applied if more symbols are exported. (2)
Also, some toolchains hide symbols by default breaking the existing
logic eventually causing linker errors.

Since internal symbols are not intended to be used outside of the
project, we can compile them into object files and use exactly the same
binary code both for the final build and the tests without relying on
conditionals.

By default, all symbols are now hidden unless annotated as public.
Internal symbols are explicitly marked as not being exported in case
users chose not to hide symbols by default.

Change-Id: I589dd10be2f6f438508783cf99d141af0120057b
This commit is contained in:
Sergiu Deitsch
2022-02-07 23:43:19 +01:00
parent c6158e0ab5
commit f90833f5fa
225 changed files with 939 additions and 721 deletions
+7 -8
View File
@@ -32,7 +32,7 @@
#define CERES_INTERNAL_NUMERIC_DIFF_TEST_UTILS_H_
#include "ceres/cost_function.h"
#include "ceres/internal/port.h"
#include "ceres/internal/export.h"
#include "ceres/sized_cost_function.h"
#include "ceres/types.h"
@@ -48,7 +48,7 @@ static constexpr unsigned int kRandomSeed = 1234;
// y1 = x1'x2 -> dy1/dx1 = x2, dy1/dx2 = x1
// y2 = (x1'x2)^2 -> dy2/dx1 = 2 * x2 * (x1'x2), dy2/dx2 = 2 * x1 * (x1'x2)
// y3 = x2'x2 -> dy3/dx1 = 0, dy3/dx2 = 2 * x2
class CERES_EXPORT_INTERNAL EasyFunctor {
class CERES_NO_EXPORT EasyFunctor {
public:
bool operator()(const double* x1, const double* x2, double* residuals) const;
void ExpectCostFunctionEvaluationIsNearlyCorrect(
@@ -72,14 +72,14 @@ class EasyCostFunction : public SizedCostFunction<3, 5, 5> {
//
// dy1/dx1 = x2 * cos(x1'x2), dy1/dx2 = x1 * cos(x1'x2)
// dy2/dx1 = -x2 * exp(-x1'x2 / 10) / 10, dy2/dx2 = -x2 * exp(-x1'x2 / 10) / 10
class CERES_EXPORT TranscendentalFunctor {
class CERES_NO_EXPORT TranscendentalFunctor {
public:
bool operator()(const double* x1, const double* x2, double* residuals) const;
void ExpectCostFunctionEvaluationIsNearlyCorrect(
const CostFunction& cost_function, NumericDiffMethodType method) const;
};
class CERES_EXPORT_INTERNAL TranscendentalCostFunction
class CERES_EXPORT TranscendentalCostFunction
: public SizedCostFunction<2, 5, 5> {
public:
bool Evaluate(double const* const* parameters,
@@ -93,7 +93,7 @@ class CERES_EXPORT_INTERNAL TranscendentalCostFunction
};
// y = exp(x), dy/dx = exp(x)
class CERES_EXPORT_INTERNAL ExponentialFunctor {
class CERES_NO_EXPORT ExponentialFunctor {
public:
bool operator()(const double* x1, double* residuals) const;
void ExpectCostFunctionEvaluationIsNearlyCorrect(
@@ -115,7 +115,7 @@ class ExponentialCostFunction : public SizedCostFunction<1, 1> {
// Test adaptive numeric differentiation by synthetically adding random noise
// to a functor.
// y = x^2 + [random noise], dy/dx ~ 2x
class CERES_EXPORT_INTERNAL RandomizedFunctor {
class CERES_NO_EXPORT RandomizedFunctor {
public:
RandomizedFunctor(double noise_factor, unsigned int random_seed)
: noise_factor_(noise_factor), random_seed_(random_seed) {}
@@ -129,8 +129,7 @@ class CERES_EXPORT_INTERNAL RandomizedFunctor {
unsigned int random_seed_;
};
class CERES_EXPORT_INTERNAL RandomizedCostFunction
: public SizedCostFunction<1, 1> {
class CERES_EXPORT RandomizedCostFunction : public SizedCostFunction<1, 1> {
public:
RandomizedCostFunction(double noise_factor, unsigned int random_seed)
: functor_(noise_factor, random_seed) {}