Building DWF-to-JSON 3D Extraction Libraries on Linux
File Permissions and Environment Setup
Configure executable privileges for build scripts:
chmod u+x configure.sh
chmod -R 755 ./
Install the required compilation toolchani: automake 1.4.1, autoconf, libtool, and CMake. For CentOS environments, replace OpenJDK with the Oracle JDK.
Build System Fundamentals
CMake provides cross-platform project management, generating native Makefiles or IDE projects from CMakeLists.txt definitions. For Linux development, small projects may use hand-written Makefiles, while complex cross-platform codebases benefit from CMake's abstraction.
Core CMake Directives
cmake_minimum_required(VERSION 3.10)
project(GeometryParser)
aux_source_directory(. SRC_LIST)
add_subdirectory(math)
add_executable(ParserApp main.cpp)
target_link_libraries(ParserApp MathUtils)
Subdirectory library configuration:
aux_source_directory(. LIB_SOURCES)
add_library(MathUtils ${LIB_SOURCES})
Essential Variables
| Variable | Purpose |
|---|---|
CMAKE_SOURCE_DIR |
Root project path containing top-level CMakeLists.txt |
CMAKE_BINARY_DIR |
Build output directory (typically ./build) |
CMAKE_CXX_STANDARD |
C++ standard enforcement (e.g., set(CMAKE_CXX_STANDARD 11)) |
CMAKE_BUILD_TYPE |
Compilation mode (Release/Debug) |
Execute compilation:
cmake -B build -S .
cmake --build build
Compiling Dependencies
JSON Processing Library
Retrieve jsoncpp 0.10.7 (newer versions may trigger hexfloat namespace errors on CentOS despite C++11 flags):
wget https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/0.10.7.tar.gz
tar -xzf 0.10.7.tar.gz
cd jsoncpp-0.10.7/
Generate both static and shared libraries:
cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_SHARED_LIBS=ON \
-DARCHIVE_INSTALL_DIR=. \
-G "Unix Makefiles" .
make && make install
DWF Core Libraries
Establish the directory hierarchy under /opt/dwf-build/, placing gnu and src folders accordingly.
DWFCore Compilation:
cd /opt/dwf-build/develop/global/build/gnu/dwfcore
./init-build.sh # Convert line endings with dos2unix if errors occur
cd ../../../src/dwfcore
CXX="g++ -std=c++11" ./configure --with-zlib=no --with-expat=no
make && make install
DWF Toolkit Compilation:
cd /opt/dwf-build/develop/global/build/gnu/dwftoolkit
./init-build.sh
cd ../../../src/dwf
CXX="g++ -std=c++11" ./configure --with-jpeg=no
make && make install
Copy artifacts to your project library path:
cp -r /usr/local/lib/* /opt/dwf-build/libs/
Project Build Configuration
Create a development structure with dev/ for sources, include/ for headers, and lib/ for third-party binaries.
CMakeLists.txt Structure
cmake_minimum_required(VERSION 3.23)
set(BASE_DIRECTORY "/opt/dwf-build")
project(dwfGeometryExtractor)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -Wall -fPIC \
-Wno-unused-variable -lpthread -luuid -lz -ldl")
include_directories(${BASE_DIRECTORY}/include)
link_directories(${BASE_DIRECTORY}/lib)
aux_source_directory(${BASE_DIRECTORY}/dev SOURCE_FILES)
# Create shared library
add_library(dwfGeometryExtractor SHARED ${SOURCE_FILES})
# Link order matters: toolkit must precede core
target_link_libraries(dwfGeometryExtractor
libjsoncpp.so
libdwftk.so
libdwfcore.so
)
Note: When linking static libraries into shared objects, position-independent code (-fPIC) is required. If errors persist, switch to shared library dependencies exclusive.
Build commands:
mkdir release && cd release
cmake ..
make
Java Native Access Integration
While JNI requires strict header management, JNA provides flexible dynamic libray invocation.
Java Interface Definition
package com.example.dwf.adapter;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class GeometryAdapter {
public interface DwfLibrary extends Library {
DwfLibrary INSTANCE = Native.load("dwfGeometryExtractor", DwfLibrary.class);
int extractGeometry(String inputPath, String outputPath);
}
public synchronized int convertFile(String dwfPath, String jsonPath) {
return DwfLibrary.INSTANCE.extractGeometry(dwfPath, jsonPath);
}
}
C++ Export Declaration
extern "C" {
int extract_geometry(const char* input_file, const char* output_file) {
// Implementation logic
return 0;
}
}
Spring Boot Deployment
Place libdwfGeometryExtractor.so in resources/linux-x86-64/. The JNA loader automatically prepends lib and appends .so, so reference the library in Java without these prefixes.
Configure Maven to prevent .so compression:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>so</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
</build>
System Diagnostics
Locate JDK installation:
echo $JAVA_HOME
# Alternative:
whereis java
Identify memory-intensive processes:
ps aux --sort=-%mem | head -n 11
Search for specific binaries:
find / -name "automake" -type f -ls 2>/dev/null
Troubleshooting HTTP Timeouts
Symptom: Model loading interrupted with HTTP 404 and java.io.IOException: Broken pipe.
Resolution: Increase Nginx proxy timeout thresholds:
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
Additionally, extend gateway server timeout configurations to prevent upstream connection termination during lengthy extraction operations.