1

I need to use AWS SDK in a project that has four configurations "Debug, RelWithDebInfo, MinSizeRel, and Release"

If I follow the instructions to build and install the SDK from source, it seems I can only have one configuration installed at a time. The docs say:

Generate the build files by running cmake. Specify on the cmake command line whether to build a Debug or Release version. Choose Debug throughout this procedure to run a debug configuration of your application code. Choose Release throughout this procedure to run a release configuration of your application code.

What is the intended usage in situations where I need to run both debug and release configurations of my application code? My project is currently in development I am frequently switching between debug and release configurations. This seems like it would be a common use case but I'm having some difficulty getting this set up.

If I just go with release config of the sdk, then when I try to build my project in debug I get:

error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in AWSTest3.hello-world.obj

If I go with the debug sdk, when I try to build my project in release I get the reverse. That all make makes sense and is what I would expect under those conditions.

I tried installing both release and debug versions in separate directories, but linking them both in my project's cmakelists.txt is a challenge.

When I put into cmakelists.txt:

find_package(AWSSDK)
find_package(AWSSDKdebug)

Cmake finds the first one and skips the second one. The reason for this it turns out is because when it finds the package in the suggested folder the next thing it does is runs AWSSDKconfig.cmake in that folder. The first thing that file does is:

if(AWSSDK_FOUND)
    return()
endif()

When the second package hits that line is quits immediately. So it's very clear they don't intend you to have two separation installations of the SDK and link to each of them independently.

If I comment out that condition in the second library and it will find both packages. Next step is to link them.

AWS recommends linking with:

target_link_libraries(${PROJECT_NAME} PUBLIC ${AWSSDK_LINK_LIBRARIES})

${AWSSDK_LINK_LIBRARIES} is a variable that is set in AWSSDKconfig.cmake. Although whenever I try to print it it seems empty. It would seem like I need to link with something like:

find_package(AWSSDK)
target_link_libraries(${PROJECT_NAME} PUBLIC optimized ${AWSSDK_LINK_LIBRARIES})
find_package(AWSSDKdebug)
target_link_libraries(${PROJECT_NAME} PUBLIC debug ${AWSSDK_LINK_LIBRARIES})

When I use the above code I get:

CMake Error at source/projects/AWSTest3.hello-world/CMakeLists.txt:59 (target_link_libraries):
  The "optimized" argument must be followed by a library. 

If I leave "optimized" or "debug" out, it all links just fine. But the functionality of those specifiers is exactly what I need.

I've tried hacking AWSSDKconfig.cmake in different ways to force it to work, but the further I go in that direction clearer it becomes that this is not the right way to go about it.

Any input would be much appreciated. Thank you!

6
  • Does this solve your problem? stackoverflow.com/questions/4080668/… Commented Jan 29, 2023 at 19:34
  • Just build each configuration into a separate directory? Commented Jan 29, 2023 at 19:37
  • Hi Alan, I tried that, per the last part of my post. The problem is the AWS SDK seems to go out of it's way to keep that from working. Commented Jan 29, 2023 at 20:03
  • Can you try using separate scripts (or script that adjusts for debug/release command line switches), or build configurations + project settings if using a Visual Studio solution? Commented Jan 29, 2023 at 20:09
  • How are you telling AWSSDKconfig.cmake where to look for the sdk? Presumably you're setting a variable? Can't you just set that variable differently for each configuration? Commented Jan 29, 2023 at 21:51

1 Answer 1

0

You should be able to do this by building and installing in separate directories. You can do this with the following cmake parameter when building the sdk:

-DCMAKE_INSTALL_PREFIX="<path-to-install>"

and then use the following to when building your application:

-DCMAKE_PREFIX_PATH="<path-of-install-folder>"

overall it might look something like this

git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp

# debug install
mkdir build-debug
cd build-debug
cmake ../aws-sdk-cpp -DBUILD_ONLY="s3;s3-crt" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="<path-to-debug-install>/debug-install"
cmake --build . --config=Debug
cmake --install . --config=Debug
cd ..

# release install
mkdir build-release
cd build-release
cmake ../aws-sdk-cpp -DBUILD_ONLY="s3;s3-crt" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="<path-to-release-install>/release-install"
cmake --build . --config=Release
cmake --install . --config=Release
cd ..

# building your application in release
cd <your build dir>
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/<path-to-release-install>/release-install"
cmake --build . --config Release
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.