Browse Source

链接库生成、使用

divide_struct_def_imp
郑敬润 1 year ago
parent
commit
d6b92a5b65
  1. 2
      .gitignore
  2. 17
      CMakeLists.txt
  3. 27
      include/Point.h
  4. 22
      lib/CMakeLists.txt
  5. 4
      lib/Point.cpp

2
.gitignore

@ -6,3 +6,5 @@
.DS_Store
# cmake build dir
build/
lib/Debug/
lib/Release/

17
CMakeLists.txt

@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.16)
#------------REQUIRED_2 ------------#
project(
WireRouting # 这里没有添加任何的目标(target)
WireRoutingProject # 这里没有添加任何的目标(target)
VERSION 1.0
DESCRIPTION "A project for wire routing" # CMake 3.9+
# C,CXX,Fortran,ASM,CUDA(CMake 3.8+),CSharp(3.8+),SWIFT(CMake 3.15+ experimental)
@ -64,7 +64,7 @@ message(STATUS "Self added CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
# igl_include(glfw) # igl_include_optional(glfw) Enable the target igl::glfw
ADD_SUBDIRECTORY(lib)
#------------REQUIRED_3 ------------#
# 使fileGLOB CMakeMake
@ -75,6 +75,12 @@ add_executable(
${SRC_DIR}
)
# add_custom_command(
# TARGET ${PROJECT_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# ${CMAKE_SOURCE_DIR}/lib/$(IntDir)/WireRouting.dll $(outdir)
# )
file(COPY ${CMAKE_SOURCE_DIR}/lib/Debug/WireRouting.dll DESTINATION ${PROJECT_BINARY_DIR}/Debug)
#------------REQUIRED_5.2 CMake ------------#
# target_link_libraries(${PROJECT_NAME} PUBLIC {lib_name1} {lib_name1} ...)
@ -93,6 +99,11 @@ else()
)
endif()
target_link_libraries(
${PROJECT_NAME} PUBLIC
${PROJECT_SOURCE_DIR}/lib/Debug/WireRouting.lib
)
#------------OPTIONAL_1.2 config.h------------#
# #include "config.h" ${PROJECT_BINARY_DIR}/config.h
@ -102,7 +113,7 @@ target_include_directories(
# INTERFACE
${PROJECT_NAME} PUBLIC
${PROJECT_BINARY_DIR} # config.h.in build
include
${CMAKE_SOURCE_DIR}/include
${TINYXML_INCLUDE_DIR} # tinyxml
${TINYXML_INCLUDE_DIRS} # pkg-config tinyxml dir
)

27
include/Point.h

@ -1,11 +1,32 @@
#pragma once
#ifdef MY_LIB_SHARED_BUILD
#ifdef _WIN32
#ifdef MY_LIB_EXPORTS
#define POINT_LIB_API __declspec(dllexport)
#else
#define POINT_LIB_API __declspec(dllimport)
#endif // MY_LIB_EXPORTS
#else
#define POINT_LIB_API
#endif // _WIN32
#else
#define POINT_LIB_API
#endif // MY_LIB_SHARED_BUILD
#include <string>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const double eps = 1e-6;
#define Equal(a, b) ((fabs(a - b) < eps) ? true : false)
struct P
extern "C" POINT_LIB_API const double eps = 1e-6;
extern "C" POINT_LIB_API bool Equal(double a, double b);
extern "C" struct POINT_LIB_API P
{
double x, y, z; // 坐标
double dx, dy, dz; // 方向

22
lib/CMakeLists.txt

@ -0,0 +1,22 @@
aux_source_directory(${CMAKE_SOURCE_DIR}/lib SRC_FILES_IN_LIB)
message(STATUS "SRC_FILES_IN_LIB: ${SRC_FILES_IN_LIB}")
add_library(WireRouting SHARED ${SRC_FILES_IN_LIB})
target_compile_definitions(WireRouting PUBLIC -DMY_LIB_SHARED_BUILD)
target_compile_definitions(WireRouting PRIVATE -DMY_LIB_EXPORTS)
INSTALL(TARGETS WireRouting DESTINATION ${CMAKE_SOURCE_DIR}/lib)
SET_TARGET_PROPERTIES(
WireRouting PROPERTIES LINKER_LANGUAGE C
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib
OUTPUT_NAME "WireRouting"
PREFIX ""
)
target_include_directories(
WireRouting PUBLIC
${CMAKE_SOURCE_DIR}/include
)

4
src/Point.cpp → lib/Point.cpp

@ -1,5 +1,9 @@
#include "Point.h"
bool Equal(double a, double b)
{
return ((fabs(a - b) < eps) ? true : false);
}
bool P::operator<(P B) const
{
Loading…
Cancel
Save