Encountering challenges when integrating cvxpygen into existing projects.
estevaoms opened this issue · comments
I'm having difficulty integrating cvxpygen into my existing project. I'm unsure how to utilize the generated code in my established project.
The compiler complains about missing files. I suspect the issue lies in my CMakeLists.txt file:
CMake
cmake_minimum_required(VERSION 3.0.0)
project(mpc)
include(CTest)
enable_testing()
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
add_subdirectory(mpc-EST)
include_directories(include ${cpg_include})
add_executable(mpc main.c ${cpg_head} ${cpg_src})
My main.c file is simply meant to print the objective function value to verify the code's functionality:
C
#include <stdio.h>
#include "cpg_workspace.h"
#include "cpg_solve.h"
int main() {
printf("Hello, World!\n");
// Solve the problem instance
cpg_solve();
// Print objective function value
printf("obj = %f\n", CPG_Result.info->obj_val);
return 0;
}
Thank you for your assistance.
I resolved the issue by adding the -lm flag to the end of the /home/vboxuser/Documents/projetos_C/C/mpc/build/CMakeFiles/mpc.dir/link.txt file. However, I'm wondering if there's a way to automate this process.
-lm
should be automatically added, see this CMake instruction. If the above persists, you might want to add
set (CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lm")
to your top-level CMakeLists.txt
.