mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.14k stars 518 forks source link

Error when parsing headers referenced includes. #83

Closed jpippy closed 11 years ago

jpippy commented 11 years ago

Just want to say, awesome project. Great concept, and it is unbelievable how easy you have made it for others.

I do have a question though. When CppSharp parses the headers I specify, I get an error about the headers that are referenced within the .h file, saying they can not be found. Mainly when they are in this format: "includes/types.h"

I am adding a folder for the includes as such:

options.IncludeDirs.Add(@"C:\Users\Joe\Documents\Testapp\lib\includes");

Then adding each header as such:

options.Headers.Add("interface.h");

Now I know I could bypass this, but I am wondering if their is a way to set ignore parameters on headers. So I could ignore certain strings? Unless there is another way of fixing this.

mydogisbox commented 11 years ago

Am I correct in thinking that interface.h is in C:\Users\Joe\Documents\Testapp\lib\includes?

I think you can just add C:\Users\Joe\Documents\Testapp\lib as an include directory.

jpippy commented 11 years ago

Thanks for the reply. The issue with that is that the headers and there corresponding folders are kind of scattered all over the place. This is a very large project with multiple libraries that use alot of the same files and alot of the internal references are wrong. The project was just ported to Windows and TBH it is a giant mess. The developer did a great job with the port but, not with the house keeping. There doesn;t seem to be an issue with CppSharp, it is the project. I am going to restructure it from top to bottom, and then give it a shot.

mydogisbox commented 11 years ago

This sounds like an unusual issue, so you're probably right that the correct way to fix it is to cleanup the project rather than change CppSharp (although you can add custom processing to CppSharp if you want it).

tritao commented 11 years ago

Please re-open if this is still an issue.

sajivthomas commented 8 years ago

I am running into the same issue while trying to create a C# wrapper for https://github.com/OpenKinect/libfreenect2 , and it has header files in different folders

tritao commented 8 years ago

Hi @sajivthomas, can you describe the issue you're experiencing in more detail?

sajivthomas commented 8 years ago

Hi @tritao whenever an include looks something like this for example:

include <libfreenect2/packet_processor.h>

It would throw parser error complaining that it cannot find packet_processor.h . The way I resolved it was to specify the full path to packet_processor.h and it worked. It works for my purposes as long as I can generate a C# wrapper.

Now, I am past all the parse errors, but there is another issue, but might need to tracked as a new issue?

Anyway I will briefly mention the issue. once its done with parsing all the header files and starts generating code it throws and error in the function 'GetVirtualCallDelegate' in this file \CppSharp\src\Generator\Generators\CSharp\CSharpTextTemplate.cs

The reason is that Driver.Delegates[method] fails since there is no entry for the key in the dictionary. The method in this case is: virtual ~DepthPacketProcessor();

I can debug the code find out what's happening, but please let me know if there are obvious mistakes I might be making or if there is known issue.

ddobrev commented 8 years ago

@sajivthomas my apologies, I have been really busy lately and I haven't been able to check this bug. However, if you manage to fix it, I would gladly take a patch.

sajivthomas commented 8 years ago

No worries, I have been very busy too and was not able to spend any time lately. Attached is a patch that got the generator working. Not sure if it causes side effects or regressions ☺

Anyway it generated the C# files but now the files won’t compile after adding to a C# project. Any help would be very much appreciated.

Thanks, Sajiv

From: Dimitar Dobrev [mailto:notifications@github.com] Sent: Wednesday, January 13, 2016 5:32 AM To: mono/CppSharp CppSharp@noreply.github.com Cc: Sajiv Thomas sajiv.thomas@identitymine.com Subject: Re: [CppSharp] Error when parsing headers referenced includes. (#83)

@sajivthomashttps://github.com/sajivthomas my apologies, I have been really busy lately and I haven't been able to check this bug. However, if you manage to fix it, I would gladly take a patch.

— Reply to this email directly or view it on GitHubhttps://github.com/mono/CppSharp/issues/83#issuecomment-171290369.

tritao commented 8 years ago

Hey @sajivthomas, I cannot see any attachment from Github. Please link it here via a Github Gist or some other method so we can take a look.

About the errors, you will also have to post them so we can help. If you can get us a way to reproduce them even better, as that way it'll be more likely we can fix them.

sajivthomas commented 8 years ago

st_branch.zip

Attaching as zip. Let me try to get you the header files or maybe the entire solution for libfreenect2

ddobrev commented 8 years ago

@sajivthomas I am afraid we cannot take this code. You have only fixed the symptom but not the problem itself - that destructor should not be missing from the delegates to begin with. However, you can definitely use this piece locally until we have the time to fix the real issue. Your suggestion of sending your solution would also help a great deal, we would be able to directly debug it and see what the problem is.

sajivthomas commented 8 years ago

I was not expecting the patch to be accepted anyway ☺. Didn’t spend a lot of time understanding the whole generator just wanted to see if I can at least get a quick and dirty solution. Anyway the source solution is uploaded here https://drive.google.com/file/d/0B6u4cYoRYGz6RlFKZmRWRkZmdmc/view?usp=sharing

/build/libfreenect2.sln is the solution and /build/freenect2.vcxproj is the project for which we want to create the C# wrapper.

Once you have made a fix could you please share you implementation of CppSharp.ILbrary, I might be missing some settings and such.

-Sajiv

From: Dimitar Dobrev [mailto:notifications@github.com] Sent: Thursday, January 14, 2016 2:19 AM To: mono/CppSharp CppSharp@noreply.github.com Cc: Sajiv Thomas sajiv.thomas@identitymine.com Subject: Re: [CppSharp] Error when parsing headers referenced includes. (#83)

@sajivthomashttps://github.com/sajivthomas I am afraid we cannot tale this code. You have only fixed the symptom but not the problem itself - that destructor should not be missing from the delegates to begin with. However, you can definitely use this piece locally until we have the time to fix the real issue. Your suggestion of sending your solution would also help a great deal, we would be able to directly debug it and see what the problem is.

— Reply to this email directly or view it on GitHubhttps://github.com/mono/CppSharp/issues/83#issuecomment-171596025.

ddobrev commented 8 years ago

@sajivthomas thank you for sharing your code but I am afraid I cannot download it, do you perhaps need to adjust the permissions?

sajivthomas commented 8 years ago

Could you try now please.

ddobrev commented 8 years ago

It works now, thank you. We'll get back to you as soon as we've been able to debug it.

ddobrev commented 8 years ago

I can see now the package only contains the wrapped library, not the wrapping project itself. Is the latter closed source?

sajivthomas commented 8 years ago

The wrapping project (.NET library) would basically just contain out put from CppSharp generator. The idea is to then reference it in a .NET application to interop with the native C++ library.

Anyway I uploaded wrapper project here - https://drive.google.com/file/d/0B6u4cYoRYGz6T0ViOThrTmx5WHc/view?usp=sharing for your reference as well. However, it does not compile. So, you would need to remove it from the solution to try the run the FreenectWrapperGenerator project.

FreenectWrapper project references the generated C# files.

ddobrev commented 8 years ago

@sajivthomas thank you. @tritao is going to be a little busy so I'll be responsible for checking the bug out. I'll let you know as soon as I have news.

tritao commented 8 years ago

By the way, it would be a good idea if you could create a new Github issue to track the problem. This issue has already been closed long ago.

sajivthomas commented 8 years ago

@tritao Done. https://github.com/mono/CppSharp/issues/610