用于读取和写入 DXF/DWG 文件的 C++ 库
A free, open-source C++ library for reading and writing DXF files in both ASCII and binary formats, with support for reading DWG files from R14 to V2015.
This project is a fork of the original libdxfrw project on SourceForge. This fork includes additional improvements, updated build configurations, comprehensive test suites, and enhanced documentation to make the library more accessible and easier to use.
For the original project, please visit: http://sourceforge.net/projects/libdxfrw
Ubuntu/Debian:
sudo apt-get install build-essential cmake libiconv-hook-devFedora/RHEL/CentOS:
sudo yum install gcc-c++ cmakemacOS (using Homebrew):
brew install cmake libiconvWindows:
The recommended build method using CMake:
# Create a build directory
mkdir build
cd build
# Configure the build
cmake .. -DCMAKE_BUILD_TYPE=Release
# Build the library
cmake --build . --config Release
# Install (optional, requires sudo on Linux/macOS)
sudo cmake --build . --config Release --target installThe library will be installed to:
/usr/local/include//usr/local/lib/libdxfrw.aAlternative build method using GNU Autotools:
# Generate configure script (optional, only if building from git)
autoreconf -vfi
# Configure the build
./configure
# Build the library
make
# Install (requires root/sudo)
sudo make installvs2013/libdxfrw.sln with Visual Studio 2013 or latervs2013/Debug/ or vs2013/Release/dwg2dxf/vs2013/dwg2dxf.sln with Visual StudioCMakeLists.txtmkdir build
cd build
cmake .. -G "Visual Studio 16 2019" -A x64
cmake --build . --config Release
cmake --build . --config Release --target installBuild portable binaries for multiple OS distributions using Docker.
Note: Dockerfiles are in
docker/directory. Build process updated from CentOS 7 (EOL) to AlmaLinux 9.
Available OS Distributions:
| OS | Tag | Use Case |
|---|---|---|
| AlmaLinux 9 | almalinux |
RHEL/CentOS compatible (CentOS successor) |
| Ubuntu 22.04 LTS | ubuntu |
Debian/Ubuntu compatible |
| Amazon Linux 2023 | amazonlinux |
AWS optimized |
| Alpine Linux | alpine |
Lightweight musl-based |
Quick Start:
# Build for single OS (creates dxfrw-{os}.tar.gz)
./docker/build-docker.sh run almalinux
./docker/build-docker.sh run ubuntu
# Build for all OS distributions
./docker/build-docker.sh run all-os
# Extract and install
sudo tar xzf dxfrw-almalinux.tar.gz -C /optManual Docker Commands (if needed):
# Build image and library
docker build -t codelibs/libdxfrw:ubuntu -f docker/Dockerfile.ubuntu .
docker run -t --rm -v `pwd`:/work codelibs/libdxfrw:ubuntu /work/build.shPush to Docker Hub:
./docker/build-docker.sh push almalinuxAfter building, you can install the library system-wide:
sudo make install
# or with CMake:
sudo cmake --build build --target installCopy the headers and library files manually:
# Copy headers
sudo cp src/*.h /usr/local/include/
# Copy library
sudo cp build/libdxfrw.a /usr/local/lib/
# Update library cache (Linux only)
sudo ldconfig……CMake:
find_library(DXFRW_LIBRARY NAMES dxfrw)
find_path(DXFRW_INCLUDE_DIR libdxfrw.h)
target_include_directories(your_target PRIVATE ${DXFRW_INCLUDE_DIR})
target_link_libraries(your_target ${DXFRW_LIBRARY})g++ command line:
g++ -o myapp myapp.cpp -ldxfrw -liconvThe library includes example programs that demonstrate usage:
Converts DWG files to DXF format:
cd dwg2dxf
# Build using the same method as the main library
./dwg2dxf input.dwg output.dxfThe source code in dwg2dxf/ serves as a comprehensive reference implementation showing how to:
Extracts text information from DWG files.
The library includes utility scripts in the bin/ directory for extracting text content from DXF/DWG files.
Extracts text entities from DWG files:
# Usage
./bin/dwg2txt
# Example
./bin/dwg2txt drawing.dwg output.txtRequirements:
dwg2text executable (built with the library)Extracts text entities from DXF files:
# Usage
./bin/dxf2txt
# Example
./bin/dxf2txt drawing.dxf output.txtRequirements:
ezdxf Python package: pip install ezdxfFeatures:
You can also use the Python script directly:
# Install ezdxf if not already installed
pip install ezdxf
# Run the script
python3 bin/dxf2txt.py input.dxf output.txtThe library includes comprehensive tests covering various aspects:
cd build
cmake ..
make
ctestOr run tests individually:
./test_basic # Basic functionality tests
./test_entities # Entity reading/writing tests
./test_polylines # Polyline tests
./test_text # Text entity tests
./test_tables # Table tests
./test_blocks # Block tests
./test_versions # DXF version compatibility tests
./test_errors # Error handling testsTest files are available in the fess-testdata repository.
libdxfrw.doxdwg2dxf/ directory for reference implementationdoxygen libdxfrw.doxThis creates HTML documentation in the doc/ directory.
libdxfrw/
├── src/ # Library source code
│ ├── intern/ # Internal implementation
│ └── *.h/cpp # Public headers and implementation
├── include/ # Public header files
├── dwg2dxf/ # DWG to DXF converter example
├── dwg2text/ # DWG to text converter example
├── tests/ # Unit tests
├── vs2013/ # Visual Studio project files
└── CMakeLists.txt # CMake build configurationContributions are welcome! Please:
This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
See the COPYING file for the full license text.
See AUTHORS file for the list of contributors.
See ChangeLog for version history and changes.
暂无开放 Issues,或尚未同步最近议题。