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

#import of .tlb files fail due to /Fo argument to cl.exe not being considered. #10710

Closed
akbyrd opened this issue Mar 21, 2023 · 6 comments
Closed
Assignees
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Milestone

Comments

@akbyrd
Copy link

akbyrd commented Mar 21, 2023

Environment

  • OS and Version: Win 10 22H2
  • VS Code Version: 1.76.2
  • C/C++ Extension Version: 1.14.4

Bug Summary and Steps to Reproduce

Bug Summary:
#import statements are not resolved in C++/CLI code. This leads to error squiggles being disabled for the entire translation unit if C_Cpp.errorSquiggles is set to enabledIfIncludesResolve which makes that setting unusable in C++/CLI codebases.

Notice the error squiggle, despite the tlb sitting right there.
image

But this compiles just fine
image

Expected behavior:
#imports should resolve

Configuration and Logs

{
	"C_Cpp.default.compilerPath": "cl.exe",
	"C_Cpp.default.compilerArgs": [ "/clr" ],
}

Other Extensions

No response

Additional context

No response

@Colengms
Copy link
Collaborator

Hi @akbyrd . I think #import was introduced to support COM and does not specifically require C++/CLI. (#using is C++/CLI specific and can be used to import managed assemblies).

When using #import, it's necessary for the compiler to generate support files, including a .tlh file. That .tlh file is required by IntelliSense. After adding the #import statement, you'll need to issue a build in order to cause those files to be generated. Once the .tlh file exists, you may also need to ensure the output location is included in your include paths.

Let me know if that resolves the issue for you. If not, could you specify exactly what error message remains associated with the squiggle?

@Colengms Colengms self-assigned this Mar 22, 2023
@Colengms Colengms added Language Service more info needed The issue report is not actionable in its current state labels Mar 22, 2023
@Colengms Colengms changed the title C++/CLI imports are not resolved #import is not resolved Mar 22, 2023
@akbyrd
Copy link
Author

akbyrd commented Mar 23, 2023

Even with the extra files present it doesn't resolve. It works if the tlh is next to the cpp, but not if it's in another directory, even if it's added to the path. It's fine if the tlb is in a another directory.

image

Here's a repro:
Bug.zip

@sean-mcmanus sean-mcmanus added bug investigate: repro This issue's repro steps needs to be investigated/confirmed and removed more info needed The issue report is not actionable in its current state labels Mar 24, 2023
@Colengms
Copy link
Collaborator

Colengms commented Mar 29, 2023

Hi @akbyrd . When I compile with cl.exe without any additional arguments, I see that the .tlh file is generated in the same directory as the including file (not the location of the .tlb file. When I run a build, the file is found where cl.exe put it. So, given the command line args you've provided, IntelliSense appears to be looking in the correct location, and this appears to be by-design.

However, a /Fo argument to cl.exe should influence the expected location for those files (if it specifies only a path, and ends with a backslash or forward slash), which is something we do not appear to be handling correctly. That is something we can fix.

@akbyrd
Copy link
Author

akbyrd commented Mar 29, 2023

Indeed, that looks like the underlying issue

@Colengms Colengms changed the title #import is not resolved #import of .tlb files fail due to /Fo argument to cl.exe not being considered. Mar 29, 2023
@Colengms Colengms removed the investigate: repro This issue's repro steps needs to be investigated/confirmed label Mar 29, 2023
@Colengms Colengms added this to the 1.15.2 milestone Mar 29, 2023
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Apr 3, 2023
@sean-mcmanus
Copy link
Collaborator

@akbyrd
Copy link
Author

akbyrd commented May 2, 2023

I'm testing the new release (1.15.4) and still running into some issues.

Issue 1
Quotes don't seem to be handled correctly.
This works:
"C_Cpp.default.compilerArgs": [ "/Iinclude", "/Foobj/" ],
This does not:
"C_Cpp.default.compilerArgs": [ "/Iinclude", "/F\"oobj/\"" ],
Same effect in settings.json or c_cpp_properties.json

Issue 2
Symbols from the tlb aren't resolving.

#import "LCDHardwareMonitor.PluginLoader.CLR.Interface.tlb"
ILHMPluginLoader* foo;

ILHMPluginLoader is one of the symbols provided by the tlb. This resolves in Visual Studio but still shows a red error squiggle in VS Code. The import resolves, but the symbol does not.

Issue 3
Should "go to definition" work on the import filename?

@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Projects
None yet
Development

No branches or pull requests

3 participants