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
Updated library exports #8198
Updated library exports #8198
Conversation
cc678f4
to
a2c3f75
Compare
@mshabunin, looks like the patch needs to be updated; sorry for not merging it earlier :( |
@vpisarev , this patch is not compatible with #8461, because I've removed all |
ab4890d
to
e3a84b8
Compare
a36469b
to
6ead355
Compare
cmake/OpenCVModule.cmake
Outdated
@@ -879,6 +878,8 @@ macro(_ocv_create_module) | |||
COMPILE_PDB_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} | |||
LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} | |||
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} | |||
DEFINE_SYMBOL CVAPI_EXPORTS | |||
POSITION_INDEPENDENT_CODE TRUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"PIC" is needed for Python/Java bindings only.
For using OpenCV with applications it is not required at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a port of block removed from OpenCVCompilerOptions.cmake. We always enable PIC because static libraries can be used to build some shared libraries, I wanted to preserve this ability.
cmake/OpenCVModule.cmake
Outdated
@@ -925,7 +921,7 @@ macro(_ocv_create_module) | |||
if(OPENCV_MODULE_${the_module}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${the_module};") | |||
foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS}) | |||
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}") | |||
if(NOT hdr2 MATCHES "private" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" ) | |||
if(NOT hdr2 MATCHES "opencv2/${the_module}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to revert this change.
#include "opencv2/cv_exports.h" | ||
|
||
// fix for Android FAT_JAVA_LIB: symbols should have default visibility even in static libraries | ||
#ifdef __ANDROID__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is not consistent with following code.
Android application native library should not export OpenCV API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We build native static libraries and "fat Java lib" for Android in one build (-DBUILD_SHARED_LIBS=OFF -DBUILD_FAT_JAVA_LIB=ON
). We need to export all symbols for the second artifact. Currently all symbols are exported in static builds on all platforms, this PR changes this behavior for all platforms except Android. I can only suggest reworking "fat Java lib" artifact, so that it will be produced same way as opencv_world module (-DBUILD_SHARED_LIBS=ON -DBUILD_opencv_world=ON -DBUILD_FAT_JAVA_LIB=ON
), but it cat take more time to investigate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fat Java library is artifact for Android manager which is deprecated.
If application doesn't use Java API (doesn't require libopencv_java.so), so there is no reason to bundle whole OpenCV code into Android application.
More accurate way is no link with application JNI library with static OpenCV libraries - libopencv_core.a/etc. So we need to drop global exported symbols from these OpenCV static libraries.
So, there are 2 different builds:
- static libopencv_<>.a with global exported symbols => libopencv_java.so
- static libopencv_<>.a without global exported symbols and without any libopencv_java.so. Useful for using OpenCV API from native C++ code only (without any OpenCV Java bindings).
#ifdef _MSC_VER | ||
#define CV_EXPORTS_TEMPLATE | ||
#else | ||
#define CV_EXPORTS_TEMPLATE CV_EXPORTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CV_EXPORTS_TEMPLATE
is not expected by bindings parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently bindings generators do not support templates, so we don't need it for now. We can easily add CV_EXPORTS_TEMPLATE_W
macro if such functionality will be implemented.
I still do not understand what kind of problem should be resolved by this patch. |
This patch does not remove CV_EXPORTS macro, it changes the macro behavior depending on build configuration: dynamic builds will have same definitions as current version does, static builds will set it to empty. |
replaces #8073
build with opencv/opencv_contrib#996
This pullrequest changes