From b8ed00bd642971877e1dfda6e0815d7211a7ace2 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 18 Apr 2013 10:30:15 +0400 Subject: [PATCH] Compile OpenCV with GCC visibility set to hidden --- 3rdparty/libjasper/CMakeLists.txt | 4 ++- CMakeLists.txt | 1 - apps/haartraining/cvboost.cpp | 4 +-- cmake/OpenCVCompilerOptions.cmake | 6 ++++ .../contrib/detection_based_tracker.hpp | 4 +-- modules/core/include/opencv2/core/cvdef.h | 4 ++- modules/core/include/opencv2/core/cvstd.hpp | 2 +- modules/core/include/opencv2/core/types_c.h | 18 ++++++++++-- modules/gpu/perf4au/main.cpp | 2 -- modules/highgui/include/opencv2/highgui.hpp | 4 +-- modules/python/src2/cv2.cpp | 6 +--- modules/ts/include/opencv2/ts.hpp | 11 +------ modules/ts/include/opencv2/ts/ts_gtest.h | 14 +-------- modules/ts/include/opencv2/ts/ts_perf.hpp | 10 ------- samples/c/latentsvmdetect.cpp | 29 ++++--------------- samples/cpp/latentsvm_multidetect.cpp | 8 ----- 16 files changed, 42 insertions(+), 85 deletions(-) diff --git a/3rdparty/libjasper/CMakeLists.txt b/3rdparty/libjasper/CMakeLists.txt index 42855e2a6d..83c0198b40 100644 --- a/3rdparty/libjasper/CMakeLists.txt +++ b/3rdparty/libjasper/CMakeLists.txt @@ -23,7 +23,9 @@ if(WIN32 AND NOT MINGW) add_definitions(-DJAS_WIN_MSVC_BUILD) endif(WIN32 AND NOT MINGW) -ocv_warnings_disable(CMAKE_C_FLAGS -Wno-implicit-function-declaration -Wno-uninitialized -Wmissing-prototypes -Wmissing-declarations -Wunused -Wshadow -Wsign-compare) +ocv_warnings_disable(CMAKE_C_FLAGS -Wno-implicit-function-declaration -Wno-uninitialized + -Wmissing-prototypes -Wmissing-declarations -Wunused -Wshadow + -Wsign-compare -Wstrict-overflow) ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 /wd4018 /wd4101 /wd4244 /wd4267 /wd4715) # vs2005 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f7ab02514..b90e166284 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -285,7 +285,6 @@ endif() # Path for build/platform -specific headers # ---------------------------------------------------------------------------- set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h") -add_definitions(-DHAVE_CVCONFIG_H) ocv_include_directories(${OPENCV_CONFIG_FILE_INCLUDE_DIR}) diff --git a/apps/haartraining/cvboost.cpp b/apps/haartraining/cvboost.cpp index dcde26c13b..4b9f24f1bc 100644 --- a/apps/haartraining/cvboost.cpp +++ b/apps/haartraining/cvboost.cpp @@ -39,9 +39,7 @@ // //M*/ -#ifdef HAVE_CVCONFIG_H - #include "cvconfig.h" -#endif +#include "cvconfig.h" #ifdef HAVE_MALLOC_H #include diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index a9baa9780d..b4da4f2bbb 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -250,6 +250,12 @@ set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS}" set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}" CACHE INTERNAL "Extra linker flags for Release build") set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}" CACHE INTERNAL "Extra linker flags for Debug build") +# set default visibility to hidden +if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_OPENCV_GCC_VERSION_NUM GREATER 399) + add_extra_compiler_option(-fvisibility=hidden) + add_extra_compiler_option(-fvisibility-inlines-hidden) +endif() + #combine all "extra" options set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}") diff --git a/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp b/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp index c3db03ab9f..c11904ea19 100644 --- a/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp +++ b/modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp @@ -1,6 +1,6 @@ #pragma once -#if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(ANDROID) +#if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(__ANDROID__) #include #include @@ -9,7 +9,7 @@ namespace cv { -class DetectionBasedTracker +class CV_EXPORTS DetectionBasedTracker { public: struct Parameters diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index c033bd3532..2fba1351f3 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -73,8 +73,10 @@ # define CV_ENABLE_UNROLLED 1 #endif -#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS +#if (defined WIN32 || defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS # define CV_EXPORTS __declspec(dllexport) +#elif defined __GNUC__ && __GNUC__ >= 4 +# define CV_EXPORTS __attribute__ ((visibility ("default"))) #else # define CV_EXPORTS #endif diff --git a/modules/core/include/opencv2/core/cvstd.hpp b/modules/core/include/opencv2/core/cvstd.hpp index 1353e0fa90..0232c6d084 100644 --- a/modules/core/include/opencv2/core/cvstd.hpp +++ b/modules/core/include/opencv2/core/cvstd.hpp @@ -174,7 +174,7 @@ public: To make it all work, you need to specialize Ptr<>::delete_obj(), like: \code - template<> void Ptr::delete_obj() { call_destructor_func(obj); } + template<> CV_EXPORTS void Ptr::delete_obj() { call_destructor_func(obj); } \endcode \note{if MyObjectType is a C++ class with a destructor, you do not need to specialize delete_obj(), diff --git a/modules/core/include/opencv2/core/types_c.h b/modules/core/include/opencv2/core/types_c.h index e95170f2c0..6aaec74f36 100644 --- a/modules/core/include/opencv2/core/types_c.h +++ b/modules/core/include/opencv2/core/types_c.h @@ -272,7 +272,11 @@ CV_INLINE double cvRandReal( CvRNG* rng ) #define IPL_BORDER_REFLECT 2 #define IPL_BORDER_WRAP 3 -typedef struct CV_EXPORTS _IplImage +typedef struct +#ifdef __cplusplus + CV_EXPORTS +#endif +_IplImage { int nSize; /* sizeof(IplImage) */ int ID; /* version (=0)*/ @@ -563,7 +567,11 @@ CV_INLINE int cvIplDepth( int type ) #define CV_MAX_DIM 32 #define CV_MAX_DIM_HEAP 1024 -typedef struct CV_EXPORTS CvMatND +typedef struct +#ifdef __cplusplus + CV_EXPORTS +#endif +CvMatND { int type; int dims; @@ -610,7 +618,11 @@ CvMatND; struct CvSet; -typedef struct CV_EXPORTS CvSparseMat +typedef struct +#ifdef __cplusplus + CV_EXPORTS +#endif +CvSparseMat { int type; int dims; diff --git a/modules/gpu/perf4au/main.cpp b/modules/gpu/perf4au/main.cpp index 47a6c4e257..afdd2e4986 100644 --- a/modules/gpu/perf4au/main.cpp +++ b/modules/gpu/perf4au/main.cpp @@ -42,9 +42,7 @@ #include -#ifdef HAVE_CVCONFIG_H #include "cvconfig.h" -#endif #include "opencv2/core.hpp" #include "opencv2/gpu.hpp" #include "opencv2/highgui.hpp" diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index 693ff7906f..f7e6119001 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -542,8 +542,8 @@ protected: Ptr writer; }; -template<> void Ptr::delete_obj(); -template<> void Ptr::delete_obj(); +template<> CV_EXPORTS void Ptr::delete_obj(); +template<> CV_EXPORTS void Ptr::delete_obj(); } // cv diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index af015eb8da..c834b1f322 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -1205,11 +1205,7 @@ static int to_ok(PyTypeObject *to) return (PyType_Ready(to) == 0); } -extern "C" -#if defined WIN32 || defined _WIN32 -__declspec(dllexport) -#endif -void initcv2(); +extern "C" CV_EXPORTS void initcv2(); void initcv2() { diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 0df6decf1d..b0416daad1 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -1,16 +1,7 @@ #ifndef __OPENCV_GTESTCV_HPP__ #define __OPENCV_GTESTCV_HPP__ -#ifdef HAVE_CVCONFIG_H -# include "cvconfig.h" -#endif - -#ifndef GTEST_CREATE_SHARED_LIBRARY -#ifdef BUILD_SHARED_LIBS -#define GTEST_LINKED_AS_SHARED_LIBRARY 1 -#endif -#endif - +#include "opencv2/core/cvdef.h" #include // for va_list #ifdef _MSC_VER diff --git a/modules/ts/include/opencv2/ts/ts_gtest.h b/modules/ts/include/opencv2/ts/ts_gtest.h index 2d1227ecdc..4bce30848f 100644 --- a/modules/ts/include/opencv2/ts/ts_gtest.h +++ b/modules/ts/include/opencv2/ts/ts_gtest.h @@ -1912,19 +1912,7 @@ using ::std::tuple_size; #endif // GTEST_HAS_SEH -#ifdef _MSC_VER - -# if GTEST_LINKED_AS_SHARED_LIBRARY -# define GTEST_API_ __declspec(dllimport) -# elif GTEST_CREATE_SHARED_LIBRARY -# define GTEST_API_ __declspec(dllexport) -# endif - -#endif // _MSC_VER - -#ifndef GTEST_API_ -# define GTEST_API_ -#endif +#define GTEST_API_ CV_EXPORTS #ifdef __GNUC__ // Ask the compiler to never inline a given function. diff --git a/modules/ts/include/opencv2/ts/ts_perf.hpp b/modules/ts/include/opencv2/ts/ts_perf.hpp index 3ed82d66ce..93e5d28656 100644 --- a/modules/ts/include/opencv2/ts/ts_perf.hpp +++ b/modules/ts/include/opencv2/ts/ts_perf.hpp @@ -1,16 +1,6 @@ #ifndef __OPENCV_TS_PERF_HPP__ #define __OPENCV_TS_PERF_HPP__ -#ifdef HAVE_CVCONFIG_H -# include "cvconfig.h" -#endif - -#ifndef GTEST_CREATE_SHARED_LIBRARY -# ifdef BUILD_SHARED_LIBS -# define GTEST_LINKED_AS_SHARED_LIBRARY 1 -# endif -#endif - #include "opencv2/core.hpp" #include "ts_gtest.h" diff --git a/samples/c/latentsvmdetect.cpp b/samples/c/latentsvmdetect.cpp index 95a81359f5..83a078e5d0 100644 --- a/samples/c/latentsvmdetect.cpp +++ b/samples/c/latentsvmdetect.cpp @@ -1,14 +1,8 @@ #include "opencv2/objdetect/objdetect_c.h" #include "opencv2/highgui/highgui_c.h" +#include "opencv2/core/utility.hpp" #include -#ifdef HAVE_CVCONFIG_H -#include -#endif -#ifdef HAVE_TBB -#include "tbb/task_scheduler_init.h" -#endif - using namespace cv; static void help() @@ -31,28 +25,17 @@ static void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detec CvSeq* detections = 0; int i = 0; int64 start = 0, finish = 0; -#ifdef HAVE_TBB - tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); - if (numThreads > 0) - { - init.initialize(numThreads); - printf("Number of threads %i\n", numThreads); - } - else - { - printf("Number of threads is not correct for TBB version"); - return; - } -#endif + + setNumThreads(numThreads); + numThreads = getNumThreads(); + printf("Number of threads %i\n", numThreads); start = cvGetTickCount(); detections = cvLatentSvmDetectObjects(image, detector, storage, 0.5f, numThreads); finish = cvGetTickCount(); printf("detection time = %.3f\n", (float)(finish - start) / (float)(cvGetTickFrequency() * 1000000.0)); + setNumThreads(-1); -#ifdef HAVE_TBB - init.terminate(); -#endif for( i = 0; i < detections->total; i++ ) { CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i ); diff --git a/samples/cpp/latentsvm_multidetect.cpp b/samples/cpp/latentsvm_multidetect.cpp index 92837a60e5..4da5506d8d 100644 --- a/samples/cpp/latentsvm_multidetect.cpp +++ b/samples/cpp/latentsvm_multidetect.cpp @@ -9,14 +9,6 @@ #include #endif -#ifdef HAVE_CVCONFIG_H -#include -#endif - -#ifdef HAVE_TBB -#include "tbb/task_scheduler_init.h" -#endif - using namespace std; using namespace cv; -- GitLab