Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"unresolved external symbol" When linking to the library #2421

Closed
TyrasNistru opened this issue Mar 30, 2023 · 15 comments
Closed

"unresolved external symbol" When linking to the library #2421

TyrasNistru opened this issue Mar 30, 2023 · 15 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@TyrasNistru
Copy link

Describe the bug

I'm trying to build a simple test program that downloads a file from a S3 bucket. I've already done that a couple of times with older versions of the SDK, but with the current version, It doesn't seems to work since I can't link properly with the library:

In older versions, I only had to link to three libraries: aws-cpp-sdk, aws-cpp-sdk-s3 and aws-cpp-sdk-transfer.

Now, even linking with all libraries generated by the build, it still complains about an unresolved external symbol.

Expected Behavior

To link and work properly

Current Behavior

It does not link, complaining about the following unresolved external symbol:

error LNK2001: unresolved external symbol "public: static unsigned __int64 const Aws::Endpoint::AWSPartitions::PartitionsBlobSize" (?PartitionsBlobSize@AWSPartitions@Endpoint@Aws@@2_KB)

Reproduction Steps

  • Build the sdk on Windows, using MS Visual Studio 2019, default settings except for the BUILD_ONLY, setting it to core;s3;transfer
  • Try to link a simple code, just trying to declare a std::shared_ptr<Aws::S3::S3Client> variable
  • Try to build, linking all the libraries generated by the SDK build (aws-cpp-sdk-transfer, aws-cpp-sdk-s3, aws-cpp-sdk-core, aws-c-auth, aws-c-cal, aws-c-common, aws-c-compression, aws-c-event-stream, aws-checksums, aws-c-http, aws-c-io, aws-c-mqtt, aws-crt-cpp, aws-c-s3, aws-c-sdkutils)

Possible Solution

No response

Additional Information/Context

No response

AWS CPP SDK version used

1.11.48

Compiler and Version used

Visual Studio 2019 (MSVC 19.29.30147.0)

Operating System and version

Windows 11 Pro 22H2 build 22621.1413

@TyrasNistru TyrasNistru added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 30, 2023
@RobertvandeVelde
Copy link

I'm having exactly the same issue on Windows 10 and Visual Studio 2022. I built and installed the 'master' branch instead of the 'main' branch and that one compiles without linker errors.

@jmklix
Copy link
Member

jmklix commented Apr 5, 2023

What are the build commands that you are using?

@jmklix jmklix added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Apr 5, 2023
@jmklix jmklix self-assigned this Apr 5, 2023
@RobertvandeVelde
Copy link

RobertvandeVelde commented Apr 5, 2023

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

  2. cmake gui 3.26: configure and generate (both with default options)

  3. windows cmd: "C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe" "C:...\aws-sdk-cpp\build\ALL_BUILD.vcxproj" -p:Configuration=Release

  4. windows cmd: "C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe" "C:...\aws-sdk-cpp\build\INSTALL.vcxproj" -p:Configuration=Release

  5. Visual Studio project properties->linker->input:
    ws-cpp-sdk-core.lib; aws-cpp-sdk-s3.lib; aws-c-auth.lib; aws-c-cal.lib; aws-c-common.lib; aws-c-compression.lib; aws-c-event-stream.lib; aws; checksums.lib; aws-c-http.lib; aws-c-io.lib; aws-c-mqtt.lib; aws-crt-cpp.lib; aws-c-s3.lib; aws-c-sdkutils.lib

  6. C:...\my_project_directory\includes\aws\ contains the following maps (copied from the SDK):
    auth; cal; checksums; common; compression; core; crt; event-stream; http; io; mqtt; s3; sdkutils

  7. source file includes:
    #include <aws/core/Aws.h>
    #include <aws/s3/S3Client.h>

As said above, I did the same steps for the 'master' branch (--branch master) and that one did not have the linker error so it compiled properly.

@SergeyRyabinin
Copy link
Contributor

Hi @RobertvandeVelde ,

It is quite strange that you encounter only following linker error.

error LNK2001: unresolved external symbol "public: static unsigned __int64 const Aws::Endpoint::AWSPartitions::PartitionsBlobSize" (?PartitionsBlobSize@AWSPartitions@Endpoint@Aws@@2_KB)

I would expect much more similar linker errors because this is not a unique variable following this C++ static const variable pattern.
Could you please make sure that the whole SDK is rebuilt from a fresh/clean git repo, and installed into the destination location.

Also, could you please specify cmake configuration you have for the SDK build and the SDK consuming app? What C++ version (11/14/17/20) are using?

C:...\my_project_directory\includes\aws\ contains the following maps (copied from the SDK):

This part is not very clear, could you please elaborate a bit? Are you saying that this dir contains SDK and CRT headers or you are talking about property "additional include dirs" setting in a VS vcxproj config?

Best regards,
Sergey

@RobertvandeVelde
Copy link

RobertvandeVelde commented Apr 5, 2023

Thanks for your reply! I will remove the current installation and then redownload, build and install the main branch, although it might take some hours. I'm using C++14 (default option). For cmake, I open cmake gui (version 3.26.2), set the source and binary directories and then press configure and generate, all with default options. After building and installing with MSBuild, I copy only the libs and headers that I currently need (for a S3 client) from the installation directory to my project directory. I took the headers from C:\Program Files (x86)\aws-cpp-sdk-all\include\aws and the libs from C:\Program Files (x86)\aws-cpp-sdk-all\bin and C:\Program Files (x86)\aws-cpp-sdk-all\lib.

Update to clarify a bit more what went wrong yesterday: when configuring/generating with cmake the parameter "Treat Warnings As Errors = off" is apparently ignored. During the subsequent build I saw the following error:

C:/Users/.../aws-sdk-cpp/src/aws-cpp-sdk-core/source/client/RequestCompression.cpp(159,64): error C2220: the followin
g warning is treated as an error (compiling source file C:\Users...\aws-sdk-cpp-build\src\aws-cpp-sdk-core\ub_core.c
pp) [C:\Users...\aws-sdk-cpp-build\src\aws-cpp-sdk-core\aws-cpp-sdk-core.vcxproj]
C:/Users/.../aws-sdk-cpp/src/aws-cpp-sdk-core/source/client/RequestCompression.cpp(159,64): warning C4267: '=': conve
rsion from 'size_t' to 'uInt', possible loss of data (compiling source file C:\Users...\aws-sdk-cpp-build\src\aws-cp
p-sdk-core\ub_core.cpp) [C:\Users...\aws-sdk-cpp-build\src\aws-cpp-sdk-core\aws-cpp-sdk-core.vcxproj]
C:/Users/.../aws-sdk-cpp/src/aws-cpp-sdk-core/source/client/RequestCompression.cpp(280,35): warning C4267: '=': conve
rsion from 'size_t' to 'uInt', possible loss of data (compiling source file C:\Users...\aws-sdk-cpp-build\src\aws-cp
p-sdk-core\ub_core.cpp) [C:\Users...\aws-sdk-cpp-build\src\aws-cpp-sdk-core\aws-cpp-sdk-core.vcxproj]

I tried to use cmake via the windows cmd and placing the build directory outside the SDK source directory but that didn't help. I also installed cmake 3.21 instead of 3.26 but it turned out that that version does not support the VS 2022 C++ compiler. I opened the SDK solution to turn the "Treat Warnings As Errors" setting off (/WX-) for all 735 projects and then it finished the SDK build without any fails. However, when copying the resulting libs and headers to my project the unresolved external symbol error appeared during the project build. I will try to build the SDK once more tomorrow although I expect the error to show up again. Otherwise I will just use the master branch since that source version builds effortlessly using the instructions on the documentation page.

Last update: I build the main source again but incorporating it still leads to the unresolved external symbol error in my project. I also get the same two warnings (conversion from 'size_t' to 'uInt', possible loss of data) that cause the SDK build to fail unless the setting "Treat Warnings As Errors" is set to /WX- in the project properties for all projects. I'm not experienced in building large external libraries so it could be that I'm missing something. For now I'll be using another source version. Thanks for the help anyway!

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Apr 6, 2023
@jmklix
Copy link
Member

jmklix commented Apr 10, 2023

Can you also try building the sdk statically with the follow cmake arguments: -DFORCE_SHARED_CRT=OFF -DBUILD_SHARED_LIBS=OFF

@jmklix jmklix added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Apr 10, 2023
@github-actions
Copy link

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Apr 13, 2023
@RobertvandeVelde
Copy link

I will try it this weekend, I'm busy with other things currently. I'll let you know.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. labels Apr 14, 2023
@RobertvandeVelde
Copy link

Turning both options off leads to errors during build for both main and master source versions. If I only turn off BUILD_SHARED_LIBS I can build the SDK, but when I use it in my project I get 103 unresolved externals for the main source. If I use master then my project builds without errors.

@D3troit98
Copy link

D3troit98 commented Jun 10, 2023

The issue still remains. I am also experiencing the same issue. So what I did to fix mine was to switched to another branch that didn't have the issue

@code-disaster
Copy link

I ran into the same issue. Built from source as shared libraries, BUILD_ONLY="s3", cmake --install into custom folder.

Then tried to compile "Hello S3" in my CMake project, but added the libraries manually, so not using AWSSDKConfig.cmake. This doesn't define USE_IMPORT_EXPORT, leading to link errors because of the now wrong AWS_XY_API declarations.

The simple fix is to define USE_IMPORT_EXPORT before including any SDK headers.

@Lovecookie
Copy link

@code-disaster This way saved my life. Thanks a lot!

@jmklix
Copy link
Member

jmklix commented Nov 9, 2023

What does your CMakeLists.txt look like?

Can you make sure that you have find_package added with all of the aws services that you are using added to it?
It should look something like this:

find_package(AWSSDK REQUIRED COMPONENTS s3 lambda transfer)

@jmklix jmklix added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Nov 9, 2023
Copy link

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Nov 12, 2023
@RoyZhang2022
Copy link

The issue exists for 1.11.21. The solution is to define USE_IMPORT_EXPORT before including any SDK headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

8 participants