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

Build with cmd not work #29

Closed
alecss131 opened this issue May 6, 2023 · 4 comments
Closed

Build with cmd not work #29

alecss131 opened this issue May 6, 2023 · 4 comments

Comments

@alecss131
Copy link

Write sample code

#import <Foundation/Foundation.h>

@interface Test : NSObject {
	int a;
}
@property int a;
-(int)mult:(int)b;
@end

@implementation Test
@synthesize a;
-(int)mult:(int)b {
	return [self a] * b;
}
@end

int main() {
	@autoreleasepool{
		Test *test = [[Test alloc] init];
		[test setA:5];
		NSLog(@"Test.a = %d", [test a]);
		int b = 6;
		NSLog(@"b = %d", b);
		NSLog(@"Test.a * b = %d", [test mult:b]);
	}
	return 0;
}

Build with

clang-cl -I C:\Library\GNUstep\x64\Debug\include -fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -Xclang -fobjc-arc -DGNUSTEP -DGNUSTEP_WITH_DLL -DGNUSTEP_RUNTIME=1 -D_NONFRAGILE_ABI=1 -D_NATIVE_OBJC_EXCEPTIONS /MDd /c main.m
clang-cl main.obj gnustep-base.lib objc.lib /MDd -o main.exe /link /LIBPATH:C:\Library\GNUstep\x64\Debug\lib

run and nothing, but simple hello world build and run fine

#import <Foundation/Foundation.h>

int main(int argc, char *argv[])
{
    @autoreleasepool {
        NSLog(@"Hello, World!");
    }
    return 0;
}

Create visual studio project. build and run fine
vs 2022 17.5.5, win sdk 10.0.22000.0, gnustep lates release

clang-cl --version
clang version 16.0.3
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

in cmd give this warning

main.obj : warning LNK4078: multiple '.CRT' sections found with different attributes (40400040)
msvcrtd.lib(initializers.obj) : warning LNK4254: section '.CRT' (C0000040) merged into '.rdata' (40000040) with different attributes

in vs project file exe is 20kb, in cmd only 16kb

forall.sln

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "forall", "forall\forall.vcxproj", "{67FB33BC-06BA-4050-846B-17F133D90889}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{67FB33BC-06BA-4050-846B-17F133D90889}.Debug|Any CPU.ActiveCfg = Debug|x64
		{67FB33BC-06BA-4050-846B-17F133D90889}.Debug|Any CPU.Build.0 = Debug|x64
		{67FB33BC-06BA-4050-846B-17F133D90889}.Release|Any CPU.ActiveCfg = Release|x64
	EndGlobalSection
EndGlobal

Directory.build.props

<Project>
  <PropertyGroup>
    <LLVMInstallDir>C:\Program Files\LLVM</LLVMInstallDir>
	  <LLVMToolsVersion>16</LLVMToolsVersion>
  </PropertyGroup>
</Project>

forall.vcxproj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>15.0</VCProjectVersion>
    <ProjectGuid>{67FB33BC-06BA-4050-846B-17F133D90889}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>forall</RootNamespace>
    <WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup>
    <PreferredToolArchitecture>x64</PreferredToolArchitecture>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>ClangCL</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>ClangCL</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
    <ExecutablePath>$(LLVMInstallDir)\bin;$(ExecutablePath);C:\Library\GNUstep\x64\Debug\bin</ExecutablePath>
    <IncludePath>$(LLVMInstallDir)\lib\clang\$(LLVMToolsVersion)\include;$(IncludePath);C:\Library\GNUstep\x64\Debug\include</IncludePath>
    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\Library\GNUstep\x64\Debug\lib</LibraryPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
    <ExecutablePath>$(LLVMInstallDir)\bin;$(ExecutablePath);C:\Library\GNUstep\x64\Release\bin</ExecutablePath>
    <IncludePath>$(LLVMInstallDir)\lib\clang\$(LLVMToolsVersion)\include;$(IncludePath);C:\Library\GNUstep\x64\Release\include</IncludePath>
    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\Library\GNUstep\x64\Release\lib</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);GNUSTEP;GNUSTEP_WITH_DLL;GNUSTEP_RUNTIME=1;_NONFRAGILE_ABI=1;_NATIVE_OBJC_EXCEPTIONS</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <AdditionalOptions>$(LlvmArchitectureSwitch) $(ClangClAdditionalOptions) %(AdditionalOptions) -fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -Xclang -fobjc-arc</AdditionalOptions>
      <CompileAs>Default</CompileAs>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);gnustep-base.lib;objc.lib</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);GNUSTEP;GNUSTEP_WITH_DLL;GNUSTEP_RUNTIME=1;_NONFRAGILE_ABI=1;_NATIVE_OBJC_EXCEPTIONS</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <AdditionalOptions>$(LlvmArchitectureSwitch) $(ClangClAdditionalOptions) %(AdditionalOptions) -fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -Xclang -fobjc-arc</AdditionalOptions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);gnustep-base.lib;objc.lib</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="main.m">
        <CompileAs></CompileAs>
    </ClCompile>
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
<ItemGroup>
  <Content Include="C:\Library\GNUstep\$(LibrariesArchitecture)\$(Configuration)\bin\*.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <TargetPath>%(Filename)%(Extension)</TargetPath>
  </Content>
</ItemGroup>
</Project>

forall.vcxproj.filters

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="Source Files">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="Header Files">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
    </Filter>
    <Filter Include="Resource Files">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="main.m">
      <Filter>Source Files</Filter>
    </ClCompile>
  </ItemGroup>
</Project>

what am I doing wrong in the console? repeated instructions one by one

@alecss131
Copy link
Author

Some changes in build (added arc) clang-cl -I C:\Library\GNUstep\x64\Debug\include -fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -Xclang -fobjc-arc -DGNUSTEP -DGNUSTEP_WITH_DLL -DGNUSTEP_RUNTIME=1 -D_NONFRAGILE_ABI=1 -D_NATIVE_OBJC_EXCEPTIONS /MDd /c main.m
and use another link command lld-link main.obj gnustep-base.lib objc.lib /out:main.exe /LIBPATH:C:\Library\GNUstep\x64\Debug\lib then run fine

@triplef
Copy link
Member

triplef commented May 8, 2023

When you get no output it sounds like the executable might have crashed, not sure if your shell would tell you about this. Can you try printing the exit code with echo %errorlevel% after running the command?

@alecss131
Copy link
Author

alecss131 commented May 8, 2023

>echo %errorlevel%
-1073741819

lld-link work without warnings and give worked exe, but interesting solve clang-cl

@triplef
Copy link
Member

triplef commented May 9, 2023

Ok so this error code is EXCEPTION_ACCESS_VIOLATION, so looks like the app is crashing for some reason.

Can you try debugging the executable e.g. by opening and running it with Visual Studio to see where it’s crashing? (You’ll have to add C:\Library\GNUstep\x64\Debug\lib to your PATH beforehand.)

I’m guessing that somehow link.exe is not producing the right output here compared to the LLVM linker, it would be interesting to see what’s going on.

@triplef triplef closed this as not planned Won't fix, can't repro, duplicate, stale Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants