Compile tests but fail linking
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
project(SVMClassifier
|
project(SVMClassifier
|
||||||
VERSION 1.0.0
|
VERSION 1.0.0
|
||||||
LANGUAGES CXX
|
LANGUAGES C CXX
|
||||||
DESCRIPTION "A C++ library for Support Vector Machine classification using PyTorch"
|
DESCRIPTION "A C++ library for Support Vector Machine classification using PyTorch"
|
||||||
HOMEPAGE_URL "https://gitea.rmontanana.es/rmontanana/SVMClassifier"
|
HOMEPAGE_URL "https://gitea.rmontanana.es/rmontanana/SVMClassifier"
|
||||||
)
|
)
|
||||||
@@ -74,14 +74,22 @@ set(HEADERS
|
|||||||
# Create library
|
# Create library
|
||||||
add_library(svm_classifier STATIC ${SOURCES} ${HEADERS})
|
add_library(svm_classifier STATIC ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
# Link libraries - Updated to use object libraries instead of static libraries
|
# Link libraries - Updated to use object libraries and BLAS if available
|
||||||
|
# target_link_libraries(svm_classifier
|
||||||
|
# PUBLIC
|
||||||
|
# ${TORCH_LIBRARIES}
|
||||||
|
# PRIVATE
|
||||||
|
# nlohmann_json::nlohmann_json
|
||||||
|
# $<TARGET_OBJECTS:libsvm_objects>
|
||||||
|
# $<TARGET_OBJECTS:liblinear_objects>
|
||||||
|
# $<$<TARGET_EXISTS:blas_functions>:blas_functions>
|
||||||
|
# )
|
||||||
target_link_libraries(svm_classifier
|
target_link_libraries(svm_classifier
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${TORCH_LIBRARIES}
|
${TORCH_LIBRARIES}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
nlohmann_json::nlohmann_json
|
nlohmann_json::nlohmann_json
|
||||||
$<TARGET_OBJECTS:libsvm_objects>
|
$<$<TARGET_EXISTS:svm_external_combined>:svm_external_combined>
|
||||||
$<TARGET_OBJECTS:liblinear_objects>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set include directories
|
# Set include directories
|
||||||
|
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
# Basic usage example
|
# Basic usage example
|
||||||
add_executable(basic_usage basic_usage.cpp)
|
add_executable(basic_usage basic_usage.cpp)
|
||||||
target_link_libraries(basic_usage PRIVATE svm_classifier)
|
target_link_libraries(basic_usage PRIVATE svm_classifier
|
||||||
|
nlohmann_json::nlohmann_json
|
||||||
|
)
|
||||||
target_include_directories(basic_usage PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
target_include_directories(basic_usage PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
||||||
target_compile_features(basic_usage PRIVATE cxx_std_17)
|
target_compile_features(basic_usage PRIVATE cxx_std_17)
|
||||||
|
|
||||||
|
@@ -73,7 +73,7 @@ void basic_svm_example()
|
|||||||
std::cout << "Dataset created:" << std::endl;
|
std::cout << "Dataset created:" << std::endl;
|
||||||
print_tensor_stats(X_train, "X_train");
|
print_tensor_stats(X_train, "X_train");
|
||||||
std::cout << "Unique classes in y_train: ";
|
std::cout << "Unique classes in y_train: ";
|
||||||
auto unique_classes = torch::unique(y_train);
|
auto unique_classes = std::get<0>(at::_unique(y_train));
|
||||||
for (int i = 0; i < unique_classes.size(0); ++i) {
|
for (int i = 0; i < unique_classes.size(0); ++i) {
|
||||||
std::cout << unique_classes[i].item<int>() << " ";
|
std::cout << unique_classes[i].item<int>() << " ";
|
||||||
}
|
}
|
||||||
|
54
external/CMakeLists.txt
vendored
54
external/CMakeLists.txt
vendored
@@ -1,4 +1,4 @@
|
|||||||
# External dependencies CMakeLists.txt - Fixed version with OBJECT libraries
|
# External dependencies CMakeLists.txt - Fixed version with proper BLAS handling
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ FetchContent_Declare(
|
|||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(liblinear)
|
FetchContent_MakeAvailable(liblinear)
|
||||||
|
|
||||||
# Build libsvm as OBJECT library to avoid export issues
|
# Build libsvm as OBJECT library
|
||||||
if(EXISTS "${libsvm_SOURCE_DIR}/svm.cpp")
|
if(EXISTS "${libsvm_SOURCE_DIR}/svm.cpp")
|
||||||
set(LIBSVM_SOURCES "${libsvm_SOURCE_DIR}/svm.cpp")
|
set(LIBSVM_SOURCES "${libsvm_SOURCE_DIR}/svm.cpp")
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ if(EXISTS "${libsvm_SOURCE_DIR}/svm.cpp")
|
|||||||
|
|
||||||
# Set properties for the object library
|
# Set properties for the object library
|
||||||
target_include_directories(libsvm_objects
|
target_include_directories(libsvm_objects
|
||||||
PRIVATE
|
PUBLIC
|
||||||
${libsvm_SOURCE_DIR}
|
${libsvm_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,8 +49,9 @@ else()
|
|||||||
set(LIBSVM_INCLUDE_DIR "" PARENT_SCOPE)
|
set(LIBSVM_INCLUDE_DIR "" PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Build liblinear as OBJECT library
|
# Build liblinear with BLAS as a static library
|
||||||
set(LIBLINEAR_SOURCES)
|
set(LIBLINEAR_SOURCES)
|
||||||
|
set(BLAS_SOURCES)
|
||||||
|
|
||||||
# Check for main liblinear source files
|
# Check for main liblinear source files
|
||||||
if(EXISTS "${liblinear_SOURCE_DIR}/linear.cpp")
|
if(EXISTS "${liblinear_SOURCE_DIR}/linear.cpp")
|
||||||
@@ -64,7 +65,7 @@ elseif(EXISTS "${liblinear_SOURCE_DIR}/newton.cpp")
|
|||||||
list(APPEND LIBLINEAR_SOURCES "${liblinear_SOURCE_DIR}/newton.cpp")
|
list(APPEND LIBLINEAR_SOURCES "${liblinear_SOURCE_DIR}/newton.cpp")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Check for BLAS files in blas directory - Fixed to ensure they're included
|
# Check for BLAS files in blas directory
|
||||||
if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
||||||
# Explicitly add the required BLAS source files
|
# Explicitly add the required BLAS source files
|
||||||
set(BLAS_FILES
|
set(BLAS_FILES
|
||||||
@@ -77,7 +78,7 @@ if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
|||||||
# Check which BLAS files actually exist and add them
|
# Check which BLAS files actually exist and add them
|
||||||
foreach(blas_file ${BLAS_FILES})
|
foreach(blas_file ${BLAS_FILES})
|
||||||
if(EXISTS ${blas_file})
|
if(EXISTS ${blas_file})
|
||||||
list(APPEND LIBLINEAR_SOURCES ${blas_file})
|
list(APPEND BLAS_SOURCES ${blas_file})
|
||||||
message(STATUS "Adding BLAS file: ${blas_file}")
|
message(STATUS "Adding BLAS file: ${blas_file}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
@@ -85,20 +86,40 @@ else()
|
|||||||
message(WARNING "BLAS directory not found in liblinear source")
|
message(WARNING "BLAS directory not found in liblinear source")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Create liblinear object library if we have source files
|
# Create liblinear with BLAS
|
||||||
if(LIBLINEAR_SOURCES)
|
if(LIBLINEAR_SOURCES)
|
||||||
|
# First create BLAS library if we have BLAS sources
|
||||||
|
if(BLAS_SOURCES)
|
||||||
|
add_library(blas_functions STATIC ${BLAS_SOURCES})
|
||||||
|
target_include_directories(blas_functions
|
||||||
|
PUBLIC ${liblinear_SOURCE_DIR}/blas
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set C language for BLAS
|
||||||
|
set_target_properties(blas_functions PROPERTIES
|
||||||
|
LINKER_LANGUAGE C
|
||||||
|
POSITION_INDEPENDENT_CODE ON
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure symbols are exported
|
||||||
|
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||||
|
target_compile_options(blas_functions PRIVATE -fvisibility=default)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Create liblinear object library
|
||||||
add_library(liblinear_objects OBJECT ${LIBLINEAR_SOURCES})
|
add_library(liblinear_objects OBJECT ${LIBLINEAR_SOURCES})
|
||||||
|
|
||||||
# Set properties for the object library
|
# Set properties for the object library
|
||||||
target_include_directories(liblinear_objects
|
target_include_directories(liblinear_objects
|
||||||
PRIVATE
|
PUBLIC
|
||||||
${liblinear_SOURCE_DIR}
|
${liblinear_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add blas directory if it exists
|
# Add blas directory if it exists
|
||||||
if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
||||||
target_include_directories(liblinear_objects
|
target_include_directories(liblinear_objects
|
||||||
PRIVATE ${liblinear_SOURCE_DIR}/blas
|
PUBLIC ${liblinear_SOURCE_DIR}/blas
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -116,7 +137,15 @@ if(LIBLINEAR_SOURCES)
|
|||||||
set(LIBLINEAR_BLAS_INCLUDE_DIR ${liblinear_SOURCE_DIR}/blas PARENT_SCOPE)
|
set(LIBLINEAR_BLAS_INCLUDE_DIR ${liblinear_SOURCE_DIR}/blas PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Export BLAS library target to parent scope if it exists
|
||||||
|
if(TARGET blas_functions)
|
||||||
|
set(LIBLINEAR_BLAS_TARGET blas_functions PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
|
||||||
message(STATUS "liblinear built with sources: ${LIBLINEAR_SOURCES}")
|
message(STATUS "liblinear built with sources: ${LIBLINEAR_SOURCES}")
|
||||||
|
if(BLAS_SOURCES)
|
||||||
|
message(STATUS "BLAS functions built as separate static library")
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
# Create minimal liblinear implementation as object library
|
# Create minimal liblinear implementation as object library
|
||||||
message(WARNING "liblinear source files not found, creating minimal implementation")
|
message(WARNING "liblinear source files not found, creating minimal implementation")
|
||||||
@@ -165,7 +194,7 @@ else()
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_library(liblinear_objects OBJECT "${MINIMAL_LIBLINEAR_DIR}/linear.cpp")
|
add_library(liblinear_objects OBJECT "${MINIMAL_LIBLINEAR_DIR}/linear.cpp")
|
||||||
target_include_directories(liblinear_objects PRIVATE ${MINIMAL_LIBLINEAR_DIR})
|
target_include_directories(liblinear_objects PUBLIC ${MINIMAL_LIBLINEAR_DIR})
|
||||||
target_compile_features(liblinear_objects PRIVATE cxx_std_17)
|
target_compile_features(liblinear_objects PRIVATE cxx_std_17)
|
||||||
|
|
||||||
set(LIBLINEAR_INCLUDE_DIR ${MINIMAL_LIBLINEAR_DIR} PARENT_SCOPE)
|
set(LIBLINEAR_INCLUDE_DIR ${MINIMAL_LIBLINEAR_DIR} PARENT_SCOPE)
|
||||||
@@ -175,4 +204,7 @@ endif()
|
|||||||
message(STATUS "External libraries configured:")
|
message(STATUS "External libraries configured:")
|
||||||
message(STATUS " - libsvm: ${libsvm_SOURCE_DIR}")
|
message(STATUS " - libsvm: ${libsvm_SOURCE_DIR}")
|
||||||
message(STATUS " - liblinear: ${liblinear_SOURCE_DIR}")
|
message(STATUS " - liblinear: ${liblinear_SOURCE_DIR}")
|
||||||
message(STATUS " - Using OBJECT libraries to avoid export issues")
|
if(TARGET blas_functions)
|
||||||
|
message(STATUS " - BLAS functions built as separate static library")
|
||||||
|
endif()
|
||||||
|
message(STATUS " - Using combination of OBJECT and STATIC libraries")
|
||||||
|
@@ -24,6 +24,7 @@ target_link_libraries(svm_classifier_tests
|
|||||||
svm_classifier
|
svm_classifier
|
||||||
Catch2::Catch2WithMain
|
Catch2::Catch2WithMain
|
||||||
nlohmann_json::nlohmann_json
|
nlohmann_json::nlohmann_json
|
||||||
|
$<$<TARGET_EXISTS:blas_functions>:blas_functions>
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set include directories - Handle external libraries dynamically
|
# Set include directories - Handle external libraries dynamically
|
||||||
@@ -32,6 +33,20 @@ target_include_directories(svm_classifier_tests
|
|||||||
${CMAKE_SOURCE_DIR}/include
|
${CMAKE_SOURCE_DIR}/include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Add Catch2 include directories explicitly
|
||||||
|
if(TARGET Catch2::Catch2)
|
||||||
|
get_target_property(CATCH2_INCLUDE_DIRS Catch2::Catch2 INTERFACE_INCLUDE_DIRECTORIES)
|
||||||
|
target_include_directories(svm_classifier_tests PRIVATE ${CATCH2_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Also add the source directory of Catch2 if available
|
||||||
|
if(catch2_SOURCE_DIR)
|
||||||
|
target_include_directories(svm_classifier_tests
|
||||||
|
PRIVATE
|
||||||
|
${catch2_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Add libsvm include directory if available
|
# Add libsvm include directory if available
|
||||||
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/../_deps/libsvm-src")
|
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/../_deps/libsvm-src")
|
||||||
target_include_directories(svm_classifier_tests
|
target_include_directories(svm_classifier_tests
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
* @brief Unit tests for DataConverter class
|
* @brief Unit tests for DataConverter class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <catch2/catch_approx.hpp>
|
||||||
#include <svm_classifier/data_converter.hpp>
|
#include <svm_classifier/data_converter.hpp>
|
||||||
#include <torch/torch.h>
|
#include <torch/torch.h>
|
||||||
|
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
* @brief Unit tests for KernelParameters class
|
* @brief Unit tests for KernelParameters class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <catch2/catch_approx.hpp>
|
||||||
#include <svm_classifier/kernel_parameters.hpp>
|
#include <svm_classifier/kernel_parameters.hpp>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <torch/torch.h>
|
#include <torch/torch.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
* @brief Unit tests for multiclass strategy classes
|
* @brief Unit tests for multiclass strategy classes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <catch2/catch_approx.hpp>
|
||||||
#include <svm_classifier/multiclass_strategy.hpp>
|
#include <svm_classifier/multiclass_strategy.hpp>
|
||||||
#include <svm_classifier/kernel_parameters.hpp>
|
#include <svm_classifier/kernel_parameters.hpp>
|
||||||
#include <svm_classifier/data_converter.hpp>
|
#include <svm_classifier/data_converter.hpp>
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
* @brief Integration tests for SVMClassifier class
|
* @brief Integration tests for SVMClassifier class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <catch2/catch_approx.hpp>
|
||||||
#include <svm_classifier/svm_classifier.hpp>
|
#include <svm_classifier/svm_classifier.hpp>
|
||||||
#include <torch/torch.h>
|
#include <torch/torch.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
Reference in New Issue
Block a user