百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

libdxfrw

> 编程语言
开源

用于读取和写入 DXF/DWG 文件的 C++ 库

610 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于读取和写入 DXF/DWG 文件的 C++ 库

libdxfrw

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.

About this Fork

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

Features

  • DXF Support: Read and write DXF files in both ASCII and binary formats
  • DWG Support: Read DWG files from AutoCAD R14 through 2015
  • Cross-Platform: Works on Linux, macOS, Windows, and other platforms
  • Multiple Build Systems: CMake, Autotools, Visual Studio, and MinGW support
  • Comprehensive API: Full access to DXF entities, objects, headers, and tables
  • Open Source: Licensed under GNU GPL v2 or later

Table of Contents

  • About this Fork
  • Features
  • Requirements
  • Building the Library
    • Linux/macOS (CMake)
    • Linux/macOS (Autotools)
    • Windows (Visual Studio)
    • Windows (CMake)
    • Docker Build
  • Installation
  • Usage
  • Examples
  • Testing
  • Documentation
  • Contributing
  • License

Requirements

Build Dependencies

  • C++ Compiler: C++11 compatible compiler (GCC, Clang, MSVC)
  • CMake: Version 3.10 or later (for CMake builds)
  • libiconv: Character encoding conversion library

Installing Dependencies

Ubuntu/Debian:

bash
sudo apt-get install build-essential cmake libiconv-hook-dev

Fedora/RHEL/CentOS:

bash
sudo yum install gcc-c++ cmake

macOS (using Homebrew):

bash
brew install cmake libiconv

Windows:

  • Visual Studio 2013 or later, or
  • MinGW with CMake

Building the Library

Linux/macOS (CMake)

The recommended build method using CMake:

bash
# 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 install

The library will be installed to:

  • Headers: /usr/local/include/
  • Library: /usr/local/lib/libdxfrw.a

Linux/macOS (Autotools)

Alternative build method using GNU Autotools:

bash
# 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 install

Windows (Visual Studio)

Using Visual Studio Solution:

  1. Open vs2013/libdxfrw.sln with Visual Studio 2013 or later
  2. Select your desired configuration (Debug/Release)
  3. Build → Build Solution (or press F7)
  4. The library will be built in vs2013/Debug/ or vs2013/Release/

Building dwg2dxf Converter:

  1. Open dwg2dxf/vs2013/dwg2dxf.sln with Visual Studio
  2. Build Solution
  3. The executable will be in the respective Debug/Release folder

Windows (CMake)

Using Visual Studio 2019 or later:

  1. Open Visual Studio
  2. File → Open → CMake → Select CMakeLists.txt
  3. Build → Build All

Using CMake Command Line:

bash
mkdir build
cd build
cmake .. -G "Visual Studio 16 2019" -A x64
cmake --build . --config Release
cmake --build . --config Release --target install

Docker Build

Build 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:

bash
# 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 /opt

Manual Docker Commands (if needed):

bash
# 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.sh

Push to Docker Hub:

bash
./docker/build-docker.sh push almalinux

Installation

After building, you can install the library system-wide:

Linux/macOS:

bash
sudo make install
# or with CMake:
sudo cmake --build build --target install

Manual Installation:

Copy the headers and library files manually:

bash
# 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

Usage

Basic Reading Example

…

Basic Writing Example

…

Linking with Your Project

CMake:

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:

bash
g++ -o myapp myapp.cpp -ldxfrw -liconv

Examples

The library includes example programs that demonstrate usage:

dwg2dxf Converter

Converts DWG files to DXF format:

bash
cd dwg2dxf
# Build using the same method as the main library
./dwg2dxf input.dwg output.dxf

The source code in dwg2dxf/ serves as a comprehensive reference implementation showing how to:

  • Read DWG files
  • Process entities and objects
  • Write DXF output

dwg2text Converter

Extracts text information from DWG files.

Utility Scripts

The library includes utility scripts in the bin/ directory for extracting text content from DXF/DWG files.

dwg2txt - DWG to Text Converter

Extracts text entities from DWG files:

bash
# Usage
./bin/dwg2txt  

# Example
./bin/dwg2txt drawing.dwg output.txt

Requirements:

  • dwg2text executable (built with the library)

dxf2txt - DXF to Text Converter

Extracts text entities from DXF files:

bash
# Usage
./bin/dxf2txt  

# Example
./bin/dxf2txt drawing.dxf output.txt

Requirements:

  • Python 3.9 or later (minimum version across all Docker build environments)
  • ezdxf Python package: pip install ezdxf

Features:

  • Supports both TEXT and MTEXT entities
  • Handles multiple DXF versions (R12 through 2018+)
  • Automatic encoding detection (UTF-8, CP932/Shift-JIS)
  • Preserves multi-line text formatting

Direct Python Usage

You can also use the Python script directly:

bash
# Install ezdxf if not already installed
pip install ezdxf

# Run the script
python3 bin/dxf2txt.py input.dxf output.txt

Testing

The library includes comprehensive tests covering various aspects:

Running Tests (CMake):

bash
cd build
cmake ..
make
ctest

Or run tests individually:

bash
./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 tests

Test Files

Test files are available in the fess-testdata repository.

Documentation

  • Original Project Website: http://sourceforge.net/projects/libdxfrw
  • API Documentation: Generate with Doxygen using libdxfrw.dox
  • Specifications: See SPECIFICATIONS.md for DXF format details
  • Examples: Check the dwg2dxf/ directory for reference implementation

Generating API Documentation:

bash
doxygen libdxfrw.dox

This creates HTML documentation in the doc/ directory.

Project Structure

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 configuration

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

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.

Authors

See AUTHORS file for the list of contributors.

Changelog

See ChangeLog for version history and changes.

Support

This Fork

  • Issues: Report bugs and request features on GitHub Issues
  • Repository: https://github.com/codelibs/libdxfrw

Original Project

  • Website: http://sourceforge.net/projects/libdxfrw

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言