aws / aws-sdk-cpp

AWS SDK for C++
Apache License 2.0
1.97k stars 1.06k forks source link

Error Linking in visual Studio 2013 #222

Closed TechBeings closed 8 years ago

TechBeings commented 8 years ago

Whenever I try linking my project with aws-cpp-sdk-core.lib and aws-cpp-sdk-s3.lib I get this error -error LNK2001: unresolved external symbol "char const * const Aws::Http::CONTENT_TYPE_HEADER" (?CONTENT_TYPE_HEADER@Http@Aws@@3PEBDEB)

I have seen that some people also had this problem, but I did not get any good reply. can someone please help.

JonathanHenson commented 8 years ago

Have you tried using the AWSSDKCPP-S3 package from NuGet?

On Thu, Jun 30, 2016 at 7:08 AM, TechBeings notifications@github.com wrote:

Whenever I try linking my project with aws-cpp-sdk-core.lib and aws-cpp-sdk-s3.lib I get this error -error LNK2001: unresolved external symbol "char const * const Aws::Http::CONTENT_TYPE_HEADER" (?CONTENT_TYPE_HEADER@Http@Aws@@3PEBDEB)

I have seen that some people also had this problem, but I did not get any good reply. can someone please help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-sdk-cpp/issues/222, or mute the thread https://github.com/notifications/unsubscribe/ADvpxTw5XVuxEFYTY4NTk0D2o0H-Pv42ks5qQ83CgaJpZM4JCMnC .

"The poet only asks to get his head into the heavens. It is the logician who seeks to get the heavens into his head. And it is his head that splits" --G. K. Chesterton-- "Orthodoxy"

JonathanHenson commented 8 years ago

Did you have any chance to try the NuGet package?

TechBeings commented 8 years ago

I tried it for a while yesterday but I got all this other errors. I am planning on trying it again this weekend intensively ,I might be doing something wrong I will let you know if it works

TechBeings commented 8 years ago

I have tried it now and it still gives me the same error as before whenever I add GetObjectRequest getObjectRequest; I have sent you an Email with the sample project I am testing with, would you please look at it and let me know what I am doing wrong. Thanks.

bretambrose commented 8 years ago

Hi, Jonathan forwarded me the google drive link and I requested access. I'll look at the issue as soon as I can download it.

bretambrose commented 8 years ago

So I just worked through some issues on your project. I was able to repeat your problem locally and here's what I did to resolve it:

In order to use the AWS libraries as DLLs, you need to define the USE_IMPORTEXPORT (yes, that name is not the best) symbol so that all of the AWS*_API macros in header files resolve to dllimports. Once you add this definition, your project builds. I did not try running it.

Additionally, I noticed that you are linking the c runtime to your project statically, but all of the AWS libraries link it in dynamically. If you switch to linking the runtime in dynamically (C/C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug DLL) then some additional warnings about standard library base class exports disappear as well.

bretambrose commented 8 years ago

After some additional investigation with Jonathan, while the above is correct and will fix your problem, it appears the real issue is that your project's nuget integration is messed up.

If you use nuget to get AWS libraries you should not have to (1) add the library path to the linker settings, (2) specify the library in the linker input, or (3) define USE_IMPORT_EXPORT because using nuget should do all of this for you invisibly. In particular, if things are integrated properly, you can just use (Project settings -> Configuration Properties -> Referenced Packages) to switch between dynamic and static linking. However, Referenced Packages does not show up in your project in its current state. So if you want to fix things properly:

Remove the USE_IMPORT_EXPORT definition that I advised you about above. Remove the library directories for core and s3 from the linker properties Remove core and s3 from the linker inputs From Manage nuget packages, uninstall core and S3 From Manage nuget packages, install core and s3

You should now be able to use (Project settings -> Configuration Properties -> Referenced Packages) and from there, switch between dynamic and static linking.

One final note: we just discovered an issue with our static nuget packages where they're being linked dynamically against the crt, but nuget is flagging consumers of them to link statically against the crt. This causes all sorts of linking errors. After some debate (between linking statically against the crt or telling nuget to have consumers link dynamically), we've decided to have the static AWS libraries link statically against the CRT. These corrected packages should show up later today. Until then, you may not be able to successfully link statically against the nuget packages.

TechBeings commented 8 years ago

Thank you for looking into it now my project builds with no errors using nuget packages.

I now have a new problem, I always hit an exception in line 136 of HttpClientFactory.cpp as soon as I try to initialize S3Client ,I expected it to use default http client. I did try to put "ENABLE_WINDOWS_CLIENT" in the Prepocessor but this does not seem to help.

The source code that I am using is running with no problems in my Mac this only happens in Windows. Can anyone help me fix this.

JonathanHenson commented 8 years ago

Are you calling AWS::InitApi() before trying to create your s3 client?

Sent from my iPhone

On Jul 7, 2016, at 7:44 AM, TechBeings notifications@github.com wrote:

Thank you for looking into it now my project builds with no errors using nuget packages.

I now have a new problem, I always hit an exception in line 136 of HttpClientFactory.cpp as soon as I try to initialize S3Client ,I expected it to use default http client. I did try to put "ENABLE_WINDOWS_CLIENT" in the Prepocessor but this does not seem to help.

The source code that I am using is running with no problems in my Mac this only happens in Windows. Can anyone help me fix this.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

TechBeings commented 8 years ago

That fixed it sorry I had not seen this blog https://aws.amazon.com/de/blogs/developer/ very helpful thanks.

flj commented 7 years ago

I have the same issue. It is not clear to me what you mean by Project settings -> Configuration Properties -> Referenced Packages I am using visual studio 2015. Going to Properties -> Configuration Properties I have no idea how to get to Referenced Packages. I have the sdks in nuget for this particular project.

Cheers