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

An error occurred when linking a static library ".lib" compiled using NativeAOT with a C++ project. #96298

Closed
dadavadd opened this issue Dec 24, 2023 · 6 comments

Comments

@dadavadd
Copy link

Compiled NativeAOT libraries:

image

The C# method before compiling to Native AOT:

image

Errors when linking the ".lib" file to my CPP project:

image

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 24, 2023
@ghost
Copy link

ghost commented Dec 24, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Compiled NativeAOT libraries:

image

The C# method before compiling to Native AOT:

image

Errors when linking the ".lib" file to my CPP project:

image

Author: dadavadd
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr

Milestone: -

@jkotas
Copy link
Member

jkotas commented Dec 24, 2023

https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrary#building-static-libraries

Static linking requires additional runtime libraries to be linked as well. You can find the list of all required libraries by publishing the project as shared library (/p:NativeLib=Shared) with detailed verbosity (-v d), and looking at the output generated by the LinkNative target.

We have #70277 opened on improving this experience.

Duplicate of #70277 .

@jkotas jkotas closed this as completed Dec 24, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 24, 2023
@dadavadd
Copy link
Author

https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrary#building-static-libraries

Static linking requires additional runtime libraries to be linked as well. You can find the list of all required libraries by publishing the project as shared library (/p:NativeLib=Shared) with detailed verbosity (-v d), and looking at the output generated by the LinkNative target.

We have #70277 opened on improving this experience.

Duplicate of #70277 .

image

I get the error: LNK1241 Cooler-Native.lib resource file(Cooler-Native.obj) already specified.

Here are all the dependencies:

image

@jkotas
Copy link
Member

jkotas commented Dec 25, 2023

error: LNK1241 Cooler-Native.lib resource file(Cooler-Native.obj) already specified.

This is known issue in .NET 8 - #95100 (comment) has workaround.

@dadavadd
Copy link
Author

error: LNK1241 Cooler-Native.lib resource file(Cooler-Native.obj) already specified.

This is known issue in .NET 8 - #95100 (comment) has workaround.

Everything works. Thank you. But there was another problem. When adding #include iostream, compilation errors appear. Without using this "#include", compilation completes without errors.
image

Before applying #include iostream:
image

Before applying #include iostream:
image

@dadavadd
Copy link
Author

Sorry. I have solved the problem. I set the "Multithreaded /MT" setting in "code generation" and added "#pragma comment(lib, "libcmt.lib")".

@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants