fintarin / Fintamath

C++ library for symbolic calculations
GNU General Public License v3.0
13 stars 6 forks source link

cppcoro not found when compiling #237

Closed clownbucko closed 3 months ago

clownbucko commented 3 months ago

When I tried to compile a C++ script using g++ and the library build file libfintamath.a (contained in a folder named lib) using the following command in a terminal (in a directory containing the main.cpp shown below) :

g++ -std=c++20 main.cpp -o main.o -lfintamath -Llib

, it returned the following :

In file included from /usr/include/c++/13/fintamath/core/MathObjectBody.hpp:7,
                 from /usr/include/c++/13/fintamath/core/IMathObject.hpp:10,
                 from /usr/include/c++/13/fintamath/expressions/Expression.hpp:13,
                 from /usr/include/c++/13/fintamath/expressions/ExpressionFunctions.hpp:3,
                 from main.cpp:2:                                                                                       
/usr/include/c++/13/fintamath/core/Parser.hpp:11:10: fatal error: cppcoro/generator.hpp: No such file or directory      
   11 | #include <cppcoro/generator.hpp>                                                                              
      |          ^~~~~~~~~~~~~~~~~~~~~~~                                                                                
compilation terminated. 

The main.cpp file called does practically nothing except include ExpressionFunctions.hpp from the library, but I'll show it for transparency :

#include <iostream>
#include "fintamath/expressions/ExpressionFunctions.hpp"

using namespace std;

int main() 
{
    return 0;

}

Am I supposed to install the cppcoro library for this to compile ? Or do I have to use a different compiler/different options ?

I used Ubuntu 24.04 LTS for this since it has the right specified versions for GMP and MPFR.

Also to be honest it's the first time I manually build and try to use a C++ static library using CMake, so I've probably missed some rookie stuff. I would really like to get this library to work for a C++ project of mine since the latter requires the handling of exact real algebraic expressions which would very likely take an huge amount of time and work to make by myself.

Thank you in advance

fintarin commented 3 months ago

Hello! Try to use this command in the root directory of the library to update submodules.

git submodule update --init --recursive

clownbucko commented 3 months ago

It still returns the same error. I have deleted the root directory, re-cloned the project and rebuilt the library after running the command you suggested. Maybe I need to also include the cppcoro source code (even if I don't really see how that will help) ? Like I said it's my first time doing this, so I don't know.

Thanks again for your fast responses

fintarin commented 3 months ago

Cppcoro is located here: ./thirdparty/cppcoro. Could you please check if it looks the same as this picture? image

clownbucko commented 3 months ago

Yes it is located here for me too if that helps

fintarin commented 3 months ago

Could you please give the cmake file of your application?

clownbucko commented 3 months ago

I'm not sure which file you're talking about. Is it ./build/cmake_install.cmake ? If yes then I attached it in a .zip file cmake_install.zip

fintarin commented 3 months ago

I suggest to start with this guide: https://cmake.org/cmake/help/latest/guide/tutorial/A%20Basic%20Starting%20Point.html#exercise-1-building-a-basic-project.

You can write a basic cmake file this way:

cmake_minimum_required(VERSION 3.5)

project(example LANGUAGES CXX)

add_executable(example main.cpp)

add_subdirectory(fintamath)
target_link_libraries(example fintamath)
clownbucko commented 3 months ago

Ok thanks for the help

clownbucko commented 3 months ago

Okay so I followed your template to make the following CMakeLists.txt file at the root of my project directory (which is /home/jowneyy_deyy/euclidea_solver_port/) (and tweaked it a bit so it could work with the library being in a separate directory etc.) :

cmake_minimum_required(VERSION 3.5)

project(euclideaSolver LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_executable(euclideaSolver main.cpp)

add_subdirectory(/home/jowneyy_deyy/fintamath /home/jowneyy_deyy/fintamath/build)
target_link_libraries(euclideaSolver /home/jowneyy_deyy/fintamath/build/lib/fintamath.a)

(the root directory of the fintamath library is at /home/jowneyy_deyy/fintamath/ to be clear, and I intended to call the executable euclideaSolver.)

I then proceeded to (attempt to) build the project in the subdirectory build and ran the command cmake .. in there, which returned the following :

-- The CXX compiler identification is GNU 13.2.0                                                                        
-- Detecting CXX compiler ABI info                                                                                      
-- Detecting CXX compiler ABI info - done                                                                               
-- Check for working CXX compiler: /usr/bin/c++ - skipped                                                               
-- Detecting CXX compile features                                                                                       
-- Detecting CXX compile features - done                                                                                
-- Version: 10.2.1                                                                                                      
-- Build type:                                                                                                          
-- Performing Test _CXX_COROUTINES_SUPPORTS_MS_FLAG                                                                     
-- Performing Test _CXX_COROUTINES_SUPPORTS_MS_FLAG - Failed                                                            
-- Performing Test _CXX_COROUTINES_SUPPORTS_MS_HEAPELIDE_FLAG                                                           
-- Performing Test _CXX_COROUTINES_SUPPORTS_MS_HEAPELIDE_FLAG - Failed                                                  
-- Performing Test _CXX_COROUTINES_SUPPORTS_TS_FLAG                                                                     
-- Performing Test _CXX_COROUTINES_SUPPORTS_TS_FLAG - Failed                                                            
-- Performing Test _CXX_COROUTINES_SUPPORTS_CORO_FLAG                                                                   
-- Performing Test _CXX_COROUTINES_SUPPORTS_CORO_FLAG - Success                                                         
-- Looking for C++ include coroutine                                                                                    
-- Looking for C++ include coroutine - found                                                                            
-- Performing Test _CXX_COROUTINES_FINAL_HEADER_COMPILES                                                                
-- Performing Test _CXX_COROUTINES_FINAL_HEADER_COMPILES - Success                                                      
-- Performing Test CXX_COROUTINES_NO_AWAIT_NEEDED                                                                       
-- Performing Test CXX_COROUTINES_NO_AWAIT_NEEDED - Success                                                             
-- Boost.Multiprecision: standalone mode ON                                                                             
-- Boost.Math: standalone mode ON                                                                                       
-- Configuring done (1.3s)                                                                                              
-- Generating done (0.0s)                                                                                               
-- Build files have been written to: /home/jowneyy_deyy/euclidea_solver_port/build 

and then after running cmake --build ., I get mostly the same error as last time :

[  1%] Building CXX object CMakeFiles/euclideaSolver.dir/main.cpp.o                                                     
In file included from /usr/include/c++/13/fintamath/core/MathObjectBody.hpp:7,                                                           
                 from /usr/include/c++/13/fintamath/core/IMathObject.hpp:10,                                                             
                 from /usr/include/c++/13/fintamath/expressions/Expression.hpp:13,                                                       
                 from /usr/include/c++/13/fintamath/expressions/ExpressionFunctions.hpp:3,                                               
                 from /home/jowneyy_deyy/euclidea_solver_port/main.cpp:2:                                               /usr/include/c++/13/fintamath/core/Parser.hpp:11:10: fatal error: cppcoro/generator.hpp: No such file or directory         
   11 | #include <cppcoro/generator.hpp>                                                                                      
      |          ^~~~~~~~~~~~~~~~~~~~~~~                                                                                
compilation terminated.                                                                                                 
gmake[2]: *** [CMakeFiles/euclideaSolver.dir/build.make:76: CMakeFiles/euclideaSolver.dir/main.cpp.o] Error 1           
gmake[1]: *** [CMakeFiles/Makefile2:201: CMakeFiles/euclideaSolver.dir/all] Error 2                                     
gmake: *** [Makefile:136: all] Error 2 

From the looks of it, I've probably missed an important step somewhere regarding cppcoro. Maybe it's somehow partly due to target_link_libraries(euclideaSolver /home/jowneyy_deyy/fintamath/build/lib/fintamath.a) in the CMakeLists.txt file which should rather be target_link_libraries(euclideaSolver /home/jowneyy_deyy/fintamath/build) but replacing with the second one returns the following warning when running cmake .. :

CMake Warning at CMakeLists.txt:11 (target_link_libraries):                                                               
  Target "euclideaSolver" requests linking to directory                                                                   
  "/home/jowneyy_deyy/fintamath/build".  Targets may link only to libraries.                                              
  CMake is dropping the item. 

which I assume is unwanted behavior.

Thanks in advance

fintarin commented 3 months ago

Try to use this one instead:

cmake_minimum_required(VERSION 3.5)

project(euclideaSolver LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_executable(euclideaSolver main.cpp)

add_subdirectory(/home/jowneyy_deyy/fintamath)
target_link_libraries(euclideaSolver fintamath::fintamath)
clownbucko commented 3 months ago

I tried to use exactly the CMakeLists.txt you suggested, but it returned an error :

-- The CXX compiler identification is GNU 13.2.0                                                                        
-- Detecting CXX compiler ABI info                                                                                      
-- Detecting CXX compiler ABI info - done                                                                               
-- Check for working CXX compiler: /usr/bin/c++ - skipped                                                               
-- Detecting CXX compile features                                                                                       
-- Detecting CXX compile features - done                                                                                
CMake Error at CMakeLists.txt:10 (add_subdirectory):                                                                      
  add_subdirectory not given a binary directory but the given source                                                      
  directory "/home/jowneyy_deyy/fintamath" is not a subdirectory of                                                      
  "/home/jowneyy_deyy/euclidea_solver_port".  When specifying an out-of-tree                                              
  source a binary directory must be explicitly specified.                                                                                                                                                                                                                                                                                                               -- Configuring incomplete, errors occurred!

but it appears to be okay since after changing add_subdirectory(/home/jowneyy_deyy/fintamath) to add_subdirectory(/home/jowneyy_deyy/fintamath /home/jowneyy_deyy/fintamath/build) in order to include the binary directory (which would be coherent with this https://cmake.org/cmake/help/latest/variable/CMAKE_BINARY_DIR.html,) it now builds without any errors and calling ./euclideaSolver prints the intended message ("It works!" here) since I modified main.cpp like so :

#include <iostream>
#include "fintamath/expressions/ExpressionFunctions.hpp"

using namespace std;
using namespace fintamath;

int main() 
{
    Expression expr;

    printf("It works!\n");

    return 0;

}

It seems to completely resolve the issue but I'll let you confirm that since you might not agree with what I did.

Thanks again

fintarin commented 3 months ago

You should drop fintamath directory inside your project directory. And then you can use add_subdirectory(fintamath).

clownbucko commented 3 months ago

Did exactly that and it worked smoothly.

I suppose the issue can be considered closed now, but I'll let you decide that.

Thank you for your patience