-x objective-c throws System.ArgumentNullException
How bug is triggered
A code snipet:
var index = ClangService.CreateIndex();
var trans = index.ParseTranslationUnit(objectivecfile, args, //that are actually containing "-x objective-c"
null,
TranslationUnitFlags.SingleFileParse);
What does it outputs ?
Value cannot be null. Parameter name: handle
Stacktrace:
at NClang.ClangObject..ctor (System.IntPtr handle) [0x00017] in <8ad3b26ee11343b1bd9b256eebdaec77>:0
at NClang.ClangTranslationUnit..ctor (System.IntPtr handle) [0x00000] in <8ad3b26ee11343b1bd9b256eebdaec77>:0
at NClang.ClangIndex.ParseTranslationUnit (System.String sourceFilename, System.String[] commandLineArgs, NClang.ClangUnsavedFile[] unsavedFiles, NClang.TranslationUnitFlags options) [0x00056] in <8ad3b26ee11343b1bd9b256eebdaec77>:0
at DemoCodeSnippet.Trigger [0x0005c] in the path of the file
at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00025] in <285579f54af44a2ca048dad6be20e190>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <285579f54af44a2ca048dad6be20e190>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <285579f54af44a2ca048dad6be20e190>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in <285579f54af44a2ca048dad6be20e190>:0
at System.Threading.ThreadHelper.ThreadStart (System.Object obj) [0x0000f] in <285579f54af44a2ca048dad6be20e190>:0
System configuration:
OS : Linux x64, Ubuntu derrivatives - KUbuntu 19.04
Thanks for the report. Unfortunately I could not reproduce the issue. I tried what you explained above but it was successful:
/sources/nclang/NClang/bin/Debug/net462$ ls
NClang.dll NClang.pdb sample.m x.cs x.exe
/sources/nclang/NClang/bin/Debug/net462$ cat x.cs
using System;
using NClang;
public class Driver
{
public static void Main (string [] args)
{
var index = ClangService.CreateIndex();
var trans = index.ParseTranslationUnit("sample.m", args, null, TranslationUnitFlags.SingleFileParse);
}
}
/sources/nclang/NClang/bin/Debug/net462$ csc x.cs -r:NClang.dll
Microsoft (R) Visual C# Compiler version 3.4.0-beta4-19569-03 (82f2e254)
Copyright (C) Microsoft Corporation. All rights reserved.
/sources/nclang/NClang/bin/Debug/net462$ mono x.exe -x objective-c
/sources/nclang/NClang/bin/Debug/net462$ cat sample.m
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"hello world");
[pool drain];
return 0;
}
Could you please provide more specific repro steps, and/or check that the above works for you? Thanks.
AnotherTry.tar.gz Here is a sample that triggers the bug, (It could be triggered by iPhoneSDK maybe) And "-x objective-c" is given in one argument else it outputs error unable to build module Foundation
The execution result would depend on the environment as I'm running this on Linux but you want to use modern ParseTranslationUnit() overload:
ClangTranslationUnit tu;
var errors = index.ParseTranslationUnit("Sample.m", Flags, null, TranslationUnitFlags.SingleFileParse, out tu);
Console.WriteLine (errors);
It resulted in ASTReadError for me.
Same for me it results to an ASTReadError (and I'm on Linux, Kubuntu as I said before)
I mean, the result is expected.
Try with the actual clang and see what it says:
~/Desktop/AnotherTry/bin/Debug$ cat Sample.m
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"hello world");
[pool drain];
return 0;
}~/Desktop/AnotherTry/bin/Debug$ clang -x objective-c Sample.m
Sample.m:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
clang -target ./target/arm64-apple-darwin14 -arch arm64 -x objective-c -fmodules -isysroot ./sdk/ Sample.m works itself while the sample given before with
static string[] Flags =
{
"-target " + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "target/arm64-apple-darwin14"),
"-isysroot " + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sdk"),
"-fmodules",
"-x objective-c",
};
with Debug.tar.gz doesn't work and fail
This does not seem to be runnable:
~/Desktop/AnotherTry/bin/Debug$ clang -target ./target/arm64-apple-darwin14 -arch arm64 -x objective-c -fmodules -isysroot ./sdk/ Sample.m
./target/arm64-apple-darwin14-ld: error while loading shared libraries: libtapi.so: cannot open shared object file: No such file or directory
This is because I installed libtapi on my computer, there it is in https://kabiroberai.com/toolchain/download.php?toolchain=ios-linux