Engine icon indicating copy to clipboard operation
Engine copied to clipboard

error compile ORE C++ 17 Ubuntu

Open pasparis opened this issue 1 year ago • 13 comments

Hello,

I am new with Open Risk Engine and would like to run it on a Mint machine(21), with CLion. I get the following compile error (C++ 17): OREData/ored/portfolio/builders/capfloor.cpp:48:1: error: control reaches end of non-void function [-Werror=return-type] 48 | } | ^

thanks in advance Pascal

pasparis avatar May 16 '23 08:05 pasparis

have you tried to build it with Cmake ?

Othmane-Ch avatar May 17 '23 09:05 Othmane-Ch

Hi Othmane, Clion is on a Mint machine(Ubuntu), Gcc compiler (c++ 17), the project uses the cmake setting; when I look at the code and stackoverflow compile error linked questions, I think that may be the code should be modified on which machine do you run ORE? Pascal

pasparis avatar May 17 '23 09:05 pasparis

I m on windows 10 .

Othmane-Ch avatar May 17 '23 09:05 Othmane-Ch

@pasparis I can't see how / why the code should be modified, can you elaborate? I am confused about the error since there is a default statement in the switch block throwing an exception.

pcaspers avatar Jul 18 '23 19:07 pcaspers

@pasparis in the file OREData/portfolio/builders/capfloor.cpp To silence the warning, you can add a return statement after the QL_FAIL macro:

default:
    QL_FAIL("Caplet volatility type, " << ovs->volatilityType() << ", not covered in EngineFactory");
    return nullptr;  // Add this line
    break;

This return statement will never actually be reached because of the exception thrown by QL_FAIL, but it should satisfy the compiler.

then in the file OREData/portfolio/builders/swaption.cpp :

The problem arises when the volatility type of the swaption volatility structure is neither ShiftedLognormal nor Normal. In this scenario, your function does not return anything.

The QL_FAIL macro throws an exception and does not return a value, which causes the error you're seeing.

You can amend this by ensuring that a value is returned regardless of the switch result. Here's how you can modify your code:

boost::shared_ptr<PricingEngine> EuropeanSwaptionEngineBuilder::engineImpl(const string& key) {
    boost::shared_ptr<IborIndex> index;
    string ccyCode = tryParseIborIndex(key, index) ? index->currency().code() : key;
    Handle<YieldTermStructure> yts = market_->discountCurve(ccyCode, configuration(MarketContext::pricing));
    Handle<SwaptionVolatilityStructure> svts = market_->swaptionVol(key, configuration(MarketContext::pricing));
    switch (svts->volatilityType()) {
    case ShiftedLognormal:
        LOG("Build BlackSwaptionEngine for currency " << ccyCode);
        return boost::make_shared<BlackSwaptionEngine>(yts, svts);
    case Normal:
        LOG("Build BachelierSwaptionEngine for currency " << ccyCode);
        return boost::make_shared<BachelierSwaptionEngine>(yts, svts);
    default:
        QL_FAIL("Swaption volatility type " << svts->volatilityType() << "not covered in EngineFactory");
    }
    return nullptr; // Added this line to ensure a value is always returned
}

Same thing, in the file OREData/portfolio/builders/yoycapfloor.cpp :

boost::shared_ptr<PricingEngine> YoYCapFloorEngineBuilder::engineImpl(const string& indexName) {
    Handle<YoYInflationIndex> yoyTs = market_->yoyInflationIndex(indexName, configuration(MarketContext::pricing));
    Handle<YieldTermStructure> discount =
        market_->discountCurve(yoyTs->currency().code(), configuration(MarketContext::pricing));
    Handle<QuantExt::YoYOptionletVolatilitySurface> ovs =
        market_->yoyCapFloorVol(indexName, configuration(MarketContext::pricing));
    if (ovs.empty())
        return boost::make_shared<QuantExt::YoYInflationBlackCapFloorEngine>(
            *yoyTs, Handle<QuantLib::YoYOptionletVolatilitySurface>(), discount);
    switch (ovs->volatilityType()) {
    case ShiftedLognormal:
        if (ovs->displacement() == 0.0) {
            LOG("Build YoYInflationBlackCapFloorEngine for inflation index " << indexName);
            return boost::make_shared<QuantExt::YoYInflationBlackCapFloorEngine>(
                *yoyTs, Handle<QuantLib::YoYOptionletVolatilitySurface>(ovs), discount);
        } else {
            LOG("Build YoYInflationUnitDisplacedBlackCapFloorEngine for inflation index " << indexName);
            return boost::make_shared<QuantExt::YoYInflationUnitDisplacedBlackCapFloorEngine>(
                *yoyTs, Handle<QuantLib::YoYOptionletVolatilitySurface>(ovs), discount);
        }
    case Normal:
        LOG("Build YoYInflationBachelierCapFloorEngine for inflation index " << indexName);
        return boost::make_shared<QuantExt::YoYInflationBachelierCapFloorEngine>(
            *yoyTs, Handle<QuantLib::YoYOptionletVolatilitySurface>(ovs), discount);
    default:
        QL_FAIL("Caplet volatility type, " << ovs->volatilityType() << ", not covered in EngineFactory");
    }
    return nullptr; // Added this line to ensure a value is always returned
}

It worked for me on WSL ubuntu

Othmane-Ch avatar Jul 20 '23 12:07 Othmane-Ch

Do you know whether this is a gcc bug? I'd rather suppress the warning for this piece of code and affected compiler versions than adding dummy code that is unreachable.

pcaspers avatar Jul 20 '23 14:07 pcaspers

@pcaspers Would you provide a new version that suppress the warnings and could you please test it on a WSL ?

Othmane-Ch avatar Jul 20 '23 16:07 Othmane-Ch

@Othmane-Ch sure we can add a suppression. Could you provide the gcc version you are using. I am asking because the build generally works on Linux with gcc, therefore I suspect we need the suppression only for certain versions of gcc.

pcaspers avatar Jul 21 '23 09:07 pcaspers

@pcaspers gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

I have actually built the project successfully . However , in the first attempt , I was using Boost 1.71.0 , in the second attempt where the built was successful , I used Boost 1.82.0.

I have faced an issue regarding linking ored to a C++ application that I m working on.

As I have built successfully ORE from master on my ubuntu WSL , I have generated the following shared libraries in the following paths :

ORE/build/QuantLib/ql/libQuantLib.so ORE/build/OREAnalytics/orea/libOREAnalytics.so ORE/build/OREData/ored/libOREData.so ORE/build/QuantExt/qle/libQuantExt.so

I am working on an application that uses all the libraries above , here is my CMakeLists :

cmake_minimum_required(VERSION 3.15) # Bump up the minimum required version for FetchContent

# Set your project name
project(RedisClient)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Fetch nlohmann/json
include(FetchContent)

FetchContent_Declare(
  json
  GIT_REPOSITORY https://github.com/nlohmann/json.git
  GIT_TAG v3.10.2
)

FetchContent_GetProperties(json)
if(NOT json_POPULATED)
  FetchContent_Populate(json)
  add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

# Define the executable target
file(GLOB SOURCES "src/*.cpp")
add_executable(RedisClient ${SOURCES})

# Add hiredis dependency
find_path(HIREDIS_HEADER hiredis)
target_include_directories(RedisClient PUBLIC ${HIREDIS_HEADER})

find_library(HIREDIS_LIB hiredis)

# Add redis-plus-plus dependency
# NOTE: this should be *sw* NOT *redis++*
find_path(REDIS_PLUS_PLUS_HEADER sw)
target_include_directories(RedisClient PUBLIC ${REDIS_PLUS_PLUS_HEADER})

find_library(REDIS_PLUS_PLUS_LIB redis++)

# Include ORE libraries
include_directories(
    /home/ochaouchaou/ORE/OREAnalytics/orea
    /home/ochaouchaou/ORE/OREData/ored
    /home/ochaouchaou/ORE/QuantLib/ql
    /home/ochaouchaou/ORE/QuantExt/qle
)

# Find the ORE libraries
find_library(OREAnalytics_LIB OREAnalytics PATHS /home/ochaouchaou/ORE/build/OREAnalytics/orea)
find_library(OREData_LIB OREData PATHS /home/ochaouchaou/ORE/build/OREData/ored)
find_library(QuantLib_LIB QuantLib PATHS /home/ochaouchaou/ORE/build/QuantLib/ql)
find_library(QuantExt_LIB QuantExt PATHS /home/ochaouchaou/ORE/build/QuantExt/qle)

# Find the threads package
find_package(Threads REQUIRED)

# Link libraries
target_link_libraries(RedisClient PRIVATE
  nlohmann_json::nlohmann_json
  ${HIREDIS_LIB}
  ${REDIS_PLUS_PLUS_LIB}
  ${CMAKE_THREAD_LIBS_INIT}
  ${OREAnalytics_LIB}
  ${OREData_LIB}
  ${QuantLib_LIB}
  ${QuantExt_LIB}
)

My project tree is :

├── ORE │ ├── App │ ├── CMakeCache.txt │ ├── CMakeFiles │ ├── CMakeLists.txt │ ├── CMakePresets.json │ ├── CPackConfig.cmake │ ├── CPackSourceConfig.cmake │ ├── CTestTestfile.cmake │ ├── DartConfiguration.tcl │ ├── Docker │ ├── Docs │ ├── Examples │ ├── FrontEnd │ ├── Makefile │ ├── News.txt │ ├── OREAnalytics │ ├── OREData │ ├── ORETest │ ├── QuantExt │ ├── QuantLib │ ├── README.md │ ├── Testing │ ├── ThirdPartyLibs │ ├── Tools │ ├── build │ ├── cmake │ ├── cmake_install.cmake │ ├── license.txt │ ├── licenseheader.txt │ ├── ore.props │ ├── runCmakeVS.cmd │ └── xsd ├── RedisClient │ ├── CMakeLists.txt │ ├── build │ └── src ├── Sender.cpp ├── Sender.hpp ├── TradeSerializer.cpp ├── TradeSerializer.hpp └── main.cpp

root@LOCHA01:/home/ochaouchaou/RedisClient/build# make VERBOSE=1
/usr/bin/cmake -S/home/ochaouchaou/RedisClient -B/home/ochaouchaou/RedisClient/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/ochaouchaou/RedisClient/build/CMakeFiles /home/ochaouchaou/RedisClient/build//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/ochaouchaou/RedisClient/build'
make  -f CMakeFiles/RedisClient.dir/build.make CMakeFiles/RedisClient.dir/depend
make[2]: Entering directory '/home/ochaouchaou/RedisClient/build'
cd /home/ochaouchaou/RedisClient/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/ochaouchaou/RedisClient /home/ochaouchaou/RedisClient /home/ochaouchaou/RedisClient/build /home/ochaouchaou/RedisClient/build /home/ochaouchaou/RedisClient/build/CMakeFiles/RedisClient.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/ochaouchaou/RedisClient/build'
make  -f CMakeFiles/RedisClient.dir/build.make CMakeFiles/RedisClient.dir/build
make[2]: Entering directory '/home/ochaouchaou/RedisClient/build'
[ 25%] Building CXX object CMakeFiles/RedisClient.dir/src/Sender.cpp.o
/usr/bin/c++ -DJSON_DIAGNOSTICS=0 -DJSON_USE_IMPLICIT_CONVERSIONS=1 -I/home/ochaouchaou/ORE/OREAnalytics/orea -I/home/ochaouchaou/ORE/OREData/ored -I/home/ochaouchaou/ORE/QuantLib/ql -I/home/ochaouchaou/ORE/QuantExt/qle -I/home/ochaouchaou/RedisClient/build/_deps/json-src/single_include -std=gnu++17 -MD -MT CMakeFiles/RedisClient.dir/src/Sender.cpp.o -MF CMakeFiles/RedisClient.dir/src/Sender.cpp.o.d -o CMakeFiles/RedisClient.dir/src/Sender.cpp.o -c /home/ochaouchaou/RedisClient/src/Sender.cpp
[ 50%] Building CXX object CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o
/usr/bin/c++ -DJSON_DIAGNOSTICS=0 -DJSON_USE_IMPLICIT_CONVERSIONS=1 -I/home/ochaouchaou/ORE/OREAnalytics/orea -I/home/ochaouchaou/ORE/OREData/ored -I/home/ochaouchaou/ORE/QuantLib/ql -I/home/ochaouchaou/ORE/QuantExt/qle -I/home/ochaouchaou/RedisClient/build/_deps/json-src/single_include -std=gnu++17 -MD -MT CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o -MF CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o.d -o CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o -c /home/ochaouchaou/RedisClient/src/TradeSerializer.cpp
/home/ochaouchaou/RedisClient/src/TradeSerializer.cpp:4:10: fatal error: ored/portfolio/trade.hpp: No such file or directory
   4 | #include <ored/portfolio/trade.hpp>
     |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/RedisClient.dir/build.make:90: CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o] Error 1
make[2]: Leaving directory '/home/ochaouchaou/RedisClient/build'
make[1]: *** [CMakeFiles/Makefile2:99: CMakeFiles/RedisClient.dir/all] Error 2
make[1]: Leaving directory '/home/ochaouchaou/RedisClient/build'
make: *** [Makefile:91: all] Error 2

when I include the absolute path , it generates this :

 [ 25%] Building CXX object CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o
/usr/bin/c++ -DJSON_DIAGNOSTICS=0 -DJSON_USE_IMPLICIT_CONVERSIONS=1 -I/home/ochaouchaou/ORE/OREAnalytics/orea -I/home/ochaouchaou/ORE/OREData/ored -I/home/ochaouchaou/ORE/QuantLib/ql -I/home/ochaouchaou/ORE/QuantExt/qle -I/home/ochaouchaou/RedisClient/build/_deps/json-src/single_include -std=gnu++17 -MD -MT CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o -MF CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o.d -o CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o -c /home/ochaouchaou/RedisClient/src/TradeSerializer.cpp
In file included from /home/ochaouchaou/RedisClient/src/TradeSerializer.cpp:4:
/home/ochaouchaou/ORE/OREData/ored/portfolio/trade.hpp:26:10: fatal error: ored/portfolio/enginefactory.hpp: No such file or directory
   26 | #include <ored/portfolio/enginefactory.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/RedisClient.dir/build.make:90: CMakeFiles/RedisClient.dir/src/TradeSerializer.cpp.o] Error 1
make[2]: Leaving directory '/home/ochaouchaou/RedisClient/build'
make[1]: *** [CMakeFiles/Makefile2:99: CMakeFiles/RedisClient.dir/all] Error 2
make[1]: Leaving directory '/home/ochaouchaou/RedisClient/build'
make: *** [Makefile:91: all] Error 2

Any Idea on how to solve this ?

Othmane-Ch avatar Jul 21 '23 11:07 Othmane-Ch

thank you!

in your include directory declarations in CMakeLists.txt you should not have "ored", "orea", "qle" since these are part of the include statements in the source files

pcaspers avatar Jul 21 '23 12:07 pcaspers

@pcaspers Thank you

Othmane-Ch avatar Jul 21 '23 12:07 Othmane-Ch

@Othmane-Ch is there anything open here or are your issues resolved?

pcaspers avatar Oct 24 '23 12:10 pcaspers

Hi All @Othmane-Ch @pcaspers

Sorry to go back only now, at that time,in May I found a solution closed to the one proposed (but return 0 instead of nullptr) (I moved abroad and not able to post it) for info gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

pasparis avatar Nov 04 '23 19:11 pasparis