Android installation

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Android installation

#1 Post by bdarius » Wed, 2017-05-03, 07:37

Hello. So I have built an x86 version of dcmtk 3.6.1. Now, after make install I have a bunch of header files and shared libraries in the ndk toolchains directory. How do I use them in my application?

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 284
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Android installation

#2 Post by Jan Schlamelcher » Wed, 2017-05-03, 09:47

It of course depends on your application. I would recommend using the find_package() mechanism of CMake together with our CMake Exports to include and link DCMTK to your project. But this of course only works if your project uses CMake... Also, did you build DCMTK for Android from our git repository? I did some serious modifications to our Android support in mostly this and this commit.

bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Re: Android installation

#3 Post by bdarius » Thu, 2017-05-04, 12:58

Jan Schlamelcher wrote:It of course depends on your application. I would recommend using the find_package() mechanism of CMake together with our CMake Exports to include and link DCMTK to your project. But this of course only works if your project uses CMake... Also, did you build DCMTK for Android from our git repository? I did some serious modifications to our Android support in mostly this and this commit.
I used the public release, not the repository. Should I rebuild from the latest commit?

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 284
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Android installation

#4 Post by Jan Schlamelcher » Thu, 2017-05-04, 13:16

You should consider it, if you want to be able to update to new DCMTK versions in the future. The main difference of the current code is that you need to provide your own Android Toolchain file (the one included in DCMTK was removed since it was outdated and we do not have the resources to maintain it) and that newer NDK versions are supported. If you successfully built DCMTK you most likely did not used the newest Android NDK, right?

bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Re: Android installation

#5 Post by bdarius » Fri, 2017-05-05, 06:11

Jan Schlamelcher wrote:You should consider it, if you want to be able to update to new DCMTK versions in the future. The main difference of the current code is that you need to provide your own Android Toolchain file (the one included in DCMTK was removed since it was outdated and we do not have the resources to maintain it) and that newer NDK versions are supported. If you successfully built DCMTK you most likely did not used the newest Android NDK, right?
Correct, I used r10e. I will be trying to make use of CMake in my project today.

bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Re: Android installation

#6 Post by bdarius » Mon, 2017-05-08, 11:59

Ok, I built dcmtk from the latest commit and used ndk r12b. Got an error when building with make in the #ifdef HAVE_GETPWNAM_R block (the method was missing I suppose), but rectified it by commenting it out. Now I can't seem to be able to build with cmake in my project with the following output:

Code: Select all

-- Check for working C compiler: D:/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: D:/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
-- Check for working CXX compiler: D:/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Trying to find DCMTK expecting DCMTKConfig.cmake
-- Trying to find DCMTK expecting DCMTKConfig.cmake - failed
-- Trying to find DCMTK relying on FindDCMTK.cmake
-- Please set DCMTK_DIR and re-run configure (missing:  DCMTK_config_INCLUDE_DIR DCMTK_dcmdata_INCLUDE_DIR DCMTK_dcmimage_INCLUDE_DIR DCMTK_dcmimgle_INCLUDE_DIR DCMTK_dcmjpeg_INCLUDE_DIR DCMTK_dcmjpls_INCLUDE_DIR DCMTK_dcmnet_INCLUDE_DIR DCMTK_dcmpstat_INCLUDE_DIR DCMTK_dcmqrdb_INCLUDE_DIR DCMTK_dcmsign_INCLUDE_DIR DCMTK_dcmsr_INCLUDE_DIR DCMTK_dcmtls_INCLUDE_DIR DCMTK_ofstd_INCLUDE_DIR DCMTK_oflog_INCLUDE_DIR DCMTK_LIBRARIES) 
-- Trying to find DCMTK relying on FindDCMTK.cmake - ok
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev/trunk/eScrollAndroid/app/.externalNativeBuild/cmake/debug/x86
CmakeLists.txt

Code: Select all

cmake_minimum_required(VERSION 2.8)
project(dcmtk)
SET(DCMTK_DIR "C:/Program Files (x86)/DCMTK/include/dcmtk")
find_package(DCMTK)
if (DCMTK_FOUND)
  include_directories(${DCMTK_INCLUDE_DIRS})
  target_link_libraries (target_link_libraries(dcmtk ${DCMTK_LIBRARIES}))
endif (DCMTK_FOUND)
Cmake cannot find the config file, which is located in the path C:\Program Files (x86)\DCMTK\lib\cmake\dcmtk\DCMTKConfig.cmake. What am I missing here?

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 284
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Android installation

#7 Post by Jan Schlamelcher » Mon, 2017-05-08, 14:51

Modify your CMakeLists.txt to use find_package() in CONFIG mode, as explained here.

Code: Select all

- find_package(DCMTK)
+ find_package(DCMTK CONFIG)

bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Re: Android installation

#8 Post by bdarius » Tue, 2017-05-09, 08:23

Jan Schlamelcher wrote:Modify your CMakeLists.txt to use find_package() in CONFIG mode, as explained here.

Code: Select all

- find_package(DCMTK)
+ find_package(DCMTK CONFIG)
Thank you. However I am still not familiar with cmake builds. CmakeLists.txt looks like this:

Code: Select all

SET(DCMTK_DIR "C:/Program Files (x86)/DCMTK/lib/cmake/dcmtk")
find_package(DCMTK CONFIG REQUIRED)
if (DCMTK_FOUND)
  include_directories(${DCMTK_INCLUDE_DIRS})
  target_link_libraries (DCMTK ${DCMTK_LIBRARIES})
endif (DCMTK_FOUND)
It finds the configuration file, but still gives an error:

Code: Select all

CMake Error at CMakeLists.txt:9 (target_link_libraries):
  Cannot specify link libraries for target "DCMTK" which is not built by this project.
Any ideas?

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 284
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Android installation

#9 Post by Jan Schlamelcher » Tue, 2017-05-09, 09:52

Yes, thats also an error. target_link_libraries() is meant to link the libraries (in this case the DCMTK libraries) to an executable or library that you created. For example:

Code: Select all

add_executable(my_executable my_cpp_source_file)
target_link_libraries(my_executable ${DCMTK_LIBRARIES})

bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Re: Android installation

#10 Post by bdarius » Wed, 2017-05-10, 06:54

As I did not create any additional cpp files (executables or libs), I defined the executable like this:

Code: Select all

add_executable(android "")
set_target_properties(android PROPERTIES LINKER_LANGUAGE CXX)
SET(DCMTK_DIR "C:/Program Files (x86)/DCMTK/lib/cmake/dcmtk")
find_package(DCMTK CONFIG REQUIRED)
if (DCMTK_FOUND)
  include_directories(${DCMTK_INCLUDE_DIRS})
  target_link_libraries (android ${DCMTK_LIBRARIES})
endif (DCMTK_FOUND)
Now it seems no errors are produced. I can see the libraries listed in my Android project module's cpp folder. Should cmake copy the .so files to some specific directory or is the build complete by now? Because the .apk does not yet contain any libraries. Thanks

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 284
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Android installation

#11 Post by Jan Schlamelcher » Wed, 2017-05-10, 08:16

I see, so we talked about different things the whole time. The CMake Exports step ist for including DCMTK in your own C++ Android project. If this is not what you want, please clarify instead what is. If you "simply" want to use the dcmtk command line tools, you can copy them to the device using 'adb' and then execute them via a terminal emulator app of your choice or remotely via adb. I have too little experice with creating an .apk on the other hand, so I cannot tell you how to achive that (I tried it once, and it worked, but it was two years ago and I dont remember the details).

bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Re: Android installation

#12 Post by bdarius » Wed, 2017-05-10, 08:30

Jan Schlamelcher wrote:I see, so we talked about different things the whole time. The CMake Exports step ist for including DCMTK in your own C++ Android project. If this is not what you want, please clarify instead what is. If you "simply" want to use the dcmtk command line tools, you can copy them to the device using 'adb' and then execute them via a terminal emulator app of your choice or remotely via adb. I have too little experice with creating an .apk on the other hand, so I cannot tell you how to achive that (I tried it once, and it worked, but it was two years ago and I dont remember the details).
Well my intention is to include your cross compiled library in my project. I do not wish to use command line tools. I had the impression that cmake script will include these libs in my project. Was this incorrect?

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 284
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Android installation

#13 Post by Jan Schlamelcher » Wed, 2017-05-10, 09:20

I am sorry, then I still do not understand. How does your project use the DCMTK libraries without C++ source code that links to them?

bdarius
Posts: 9
Joined: Thu, 2017-04-27, 16:52

Re: Android installation

#14 Post by bdarius » Wed, 2017-05-10, 10:24

Jan Schlamelcher wrote:I am sorry, then I still do not understand. How does your project use the DCMTK libraries without C++ source code that links to them?
Well, it doesn't yet. I thought that the header files located in the include directory will be linked to the libraries during the cmake build process.

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 284
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Android installation

#15 Post by Jan Schlamelcher » Wed, 2017-05-10, 10:32

So your project uses the include files? Than you should call target_link_libraries for whatever binaries that result from the source files of your project that use the include files.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest