Compiler

RSS for tag

Discuss the various compiler and toolchain technologies used in development.

Posts under Compiler tag

108 Posts
Sort by:
Post not yet marked as solved
6 Replies
1.8k Views
Our Kotlin MPP code which compiled/linked fine using Xcode 15 Beta 2 no longer links using Xcode 15 Beta 3: ld: unknown options: -ios_simulator_version_min -sdk_version Is the option ios_simulator_version_min removed/renamed? (Intentionally?) Should Apple or JetBrains fix this? (also reported to JetBrains as KT-60238).
Posted
by
Post not yet marked as solved
4 Replies
667 Views
Dear community, I'm reading "Develop in Swift Fundamentals", and on page 89 it asks us to open a file from the downloaded file (page 9 - Download Student Materials link). I was running the last part of the exercise of page 89 and it seems I got stuck when trying to remove the last compile warning message: "1. Condition always evaluates to false" "Will never be executed" Please take a look at the screenshot, where you can see the whole code and context. I have tried to add a few breakpoints (rows 10 to 12) in order to see if they would get ignored but it looks like it's still there. Any idea how to remove / get rid of this compile warning message? Thanks, Rodrigo
Posted
by
Post not yet marked as solved
0 Replies
564 Views
I regularly see questions from folks who’ve run into problems with their third-party IDE on macOS. Specifically, the issue is that their IDE is invoking Apple’s command-line tools — things like clang and ld — and that’s failing in some way. This post collects my ideas on how to investigate, and potentially resolve, issues like this. If you have any questions or comments, please put them in a new thread here on DevForums. Tag it appropriately so that I see it. Good tags include Compiler, Linker, LLVM, and Command Line Tools. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com" Investigating Third-Party IDE Integration Problems Many third-party IDEs rely on Apple tools. For example, the IDE might run clang to compile C code or run ld to link object files. These IDEs typically don’t include the tools themselves. Rather, they rely on you to install Xcode or Apple’s Command Line Tools package. These are available at Apple > Developer > Downloads Occasionally I see folks having problems with this. They most typically report that basic stuff, like compiling a simple C program, fails with some mysterious error. If you’re having such a problem, follow the steps below to investigate it. IMPORTANT Some IDEs come with their own tools for compiling and linking. Such IDEs are not the focus of this post. If you have problems with an IDE like that, contact its vendor. Select Your Tools macOS has a concept of the current command-line tools. This can either point to the tools within Xcode or to an installed Command Line Tools package. To see which tools are currently selected, run xcode-select with the --print-path argument. This is what you’ll see if you have Xcode installed in the Applications folder: % xcode-select --print-path /Applications/Xcode.app/Contents/Developer Note All of the tools I discuss here are documented in man pages. If you’re not familiar with those, see Reading UNIX Manual Pages. And this is what you’ll see with a Command Line Tools package selected. % xcode-select --print-path /Library/Developer/CommandLineTools There are two common problems with this: It points to something you’ve deleted. It points to something unexpected. Run the command above to see the current state. If necessary, change the state using the --switch option. For example: % xcode-select --print-path /Applications/Xcode.app/Contents/Developer % clang -v Apple clang version 14.0.3 (clang-1403.0.22.14.1) … % sudo xcode-select --switch ~/XcodeZone/Xcode-beta.app % clang -v Apple clang version 15.0.0 (clang-1500.0.38.1) … I have Xcode 14.3 in the Applications foledr and thus clang runs Clang 14.0.3. I have Xcode 15.0b5 in ~/XcodeZone, so switching to that yields Clang 15.0.0. It’s possible to run one specific command with different tools. See Select Your Tools Temporarily, below. Run a Simple Test A good diagnostic test is to use the selected command-line tools to compile a trivial test program. Consider this C [1] example: % cat hello.c #include <stdio.h> int main(int argc, char ** argv) { printf("Hello Cruel World!\n"); return 0; } % clang -o hello hello.c % ./hello Hello Cruel World! IMPORTANT If possible, run this from Terminal rather than, say, over SSH. You may need to expand this test program to exercise your specific case. For example, if your program is hitting an error when it tries to import the Core Foundation framework, add that import to your test program: % cat hello.c #include <stdio.h> #include <CoreFoundation/CoreFoundation.h> int main(int argc, char ** argv) { printf("Hello Cruel World!\n"); return 0; } When you compile your test program, you might see one of these results: Your test program compiles. Your test program fails with a similar error. Your test program fails with a different error. I’ll explore each case in turn. [1] For a C++ example, see C++ Issues, below. If your test program compiles… If your test program compiles from the shell, that proves that your basic command-line tools setup is fine. If the same program fails to compile in your IDE, there’s something IDE-specific going on here. I can’t help you with that. I recommend that you escalate the issue via the support channel for your IDE. If your test program fails with a similar error… If your test program fails with an error similar to the one you’re seeing in your IDE, there are two possibilities: There’s a bug in your test program’s code. There’s an environmental issue that’s affecting your command-line tools setup. Don’t rule out the first possibility. I regularly see folks bump into problems like this, where it turns out to be a bug in their code. For a specific example, see C++ Issues, below. Assuming, however, that your test program’s code is OK, it’s time to investigate environmental issues. See Vary Your Environment, below. If your test program fails with a different error… If your test program fails with a different error, look at the test program’s code to confirm that it’s correct, and that it accurately reflects the code you’re trying to run in your IDE. Vary Your Environment If your test program fails with the same error as you’re seeing in your IDE, and you are sure that the code is correct, it’s time to look for environmental factors. I typically do this with the steps described in the next sections, which are listed from most to least complex. These steps only tell you where things are going wrong, not what is going wrong. However, that’s often enough to continue the investigation of your issue. Vary Your Shell Try running your commands in a different shell. macOS’s default shell is zsh. Try running your commands in bash instead: % bash … bash-3.2$ clang -o hello hello.c bash-3.2$ ./hello Hello Cruel World! Or if you’ve switched your shell to bash, try it in zsh. Vary Your User Account Some problems are caused by settings tied to your user account. To investigate whether that’s an issue here: Use System Settings > Users & Groups to create a new user. Log in as that user. Run your test again. Vary Your Mac Some problems are system wide, so you need to test on a different Mac. The easiest way to do that is to set up a virtual machine (VM) and run your test there. Or, if you have a separate physical Mac, run your test on that. Vary Your Site If you’re working for an organisation, they may have installed software on your Mac that causes problems. If you have a Mac at home, try running your test there. It’s also possible that your network is causing problems [1]. If you have a laptop, try taking it to a different location to see if that changes things. [1] I rarely see this when building a simple test program, but it do see it with other stuff, like code signing. C++ Issues If you’re using C++, here’s a simple test you can try: % cat hello.cpp #include <iostream> int main() { std::cout << "Hello Cruel World!\n"; } % clang++ -o hello hello.cpp % ./hello Hello Cruel World! A classic problem with C++ relates to name mangling. Consider this example: % cat hello.c #include <stdio.h> #include "hello-core.h" int main(int argc, char ** argv) { HCSayHello(); return 0; } % cat hello-core.cpp #include "hello-core.h" #include <iostream> extern void HCSayHello() { std::cout << "Hello Cruel World!\n"; } % cat hello-core.h extern void HCSayHello(); % clang -c hello.c % clang++ -c hello-core.cpp % clang++ -o hello hello.o hello-core.o Undefined symbols for architecture x86_64: "_HCSayHello", referenced from: _main in hello.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) The issue here is that C++ generates a mangled name for HCSayHello: % nm hello-core.o | grep HCSayHello 0000000000000000 T __Z10HCSayHellov whereas C uses the non-mangled name: % nm hello.o | grep HCSayHello U _HCSayHello The fix is an appropriate application of extern "C": % cat hello-core.h extern "C" { extern void HCSayHello(); }; Select Your Tools Temporarily Sometimes you want to temporarily run a command from a particular tools package. To continue my earlier example, I currently have Xcode 14.3 installed in the Applications folder and Xcode 15.0b5 in ~/XcodeZone. Xcode 14.3 is the default but I can override that with the DEVELOPER_DIR environment variable: % clang -v Apple clang version 14.0.3 (clang-1403.0.22.14.1) … % DEVELOPER_DIR=~/XcodeZone/Xcode-beta.app/Contents/Developer clang -v Apple clang version 15.0.0 (clang-1500.0.38.1) …
Posted
by
Post not yet marked as solved
1 Replies
653 Views
I'm defining a compilation condition in a SPM module that is being used by my iOS app. I'd like to be able to use the same compilation condition in my app code to determine behavior, but the condition doesn't seem to be getting set within my app. The condition is working as expected within the SPM module, just not in the iOS app that is importing the module. Package.swift excerpt target(..., swiftSettings: [.define("CONDITION", .when(configuration: .debug))] ) SPM Module #if CONDITION // Compiled and executes as expected #endif App #if CONDITION // Never compiled / triggered #endif
Posted
by
Post marked as solved
1 Replies
845 Views
Hello everybody, I am a junior on iOS app development with Swift and Xcode IDE. I want to ask about the framework compatible issue. I got a framework called "RFIDBleFramework" which provided by vendor and this framework can help connecting to a RFID device and function well. After imported this framework to my project and build, I got the following error: "Failed to build module 'RFIDBleFramework'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.7.2 (swift-5.7.2-RELEASE)', while this compiler is 'Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)'). Please select a toolchain which matches the SDK." I want to know whether that means xcode for the same major, minor, and patch version of Swift(in this case, 5.7.2) still not compatible? Or I have some mistakes on import a framework? Sorry for my poor English, if there are some additional information required, I am willing to provide. Thank you for helping. My xcode version: Version 14.2 (14C18)
Posted
by
Post not yet marked as solved
1 Replies
493 Views
With these specs which XCode version can i download? will it be enough to begin IOS Development? Mac OS Catalina macbook pro 15 inch mid 2012 processor: 2.3 GHz Quad Core Intel Core i7 Memory 8GB 1600MHz DDR3 Graphics: NVIDA geforce gt 650M 512MB Intel HD Graphics 4000 1536MB Storage: 240GB Solid State SATA Drive
Posted
by
Post marked as solved
2 Replies
970 Views
In Xcode 15 beta 6, I found that when building visionOS apps, #if os(iOS) is no longer considered part of the project. This behavior is different from beta 1 to beta 5. Is this intentional? This change has caused third-party dependencies that use #if os(iOS) and have not yet explicitly supported visionOS to fail to compile. Is there a way to switch back to the old behavior? After all, requiring all third-party dependencies to explicitly support visionOS is quite difficult.
Posted
by
Post not yet marked as solved
1 Replies
441 Views
Hi All, Instead of using embedded asm ( __asm), how could I write a arm64.s file and integrate to a command line test project with c files ? #include <stdio.h> extern int myadd(int a, int b); int main(int argc, const char * argv[]) { // insert code here... printf("Hello, World!\n"); int r = myadd( 10 , 4); return 0; } And .s file .global myadd .p2align 2 .type myadd,%function myadd: // Function "myadd" entry point. .fnstart add r0, r0, r1 // Function arguments are in R0 and R1. Add together // and put the result in R0. bx lr // Return by branching to the address in the link // register. .fnend Error -- /Users/prokashsinha/Arm/ArmAndC/asmfunction.s:9:1: error: unknown directive .type myadd,%function ^ /Users/prokashsinha/Arm/ArmAndC/asmfunction.s:12:1: error: unknown directive .fnstart ^ /Users/prokashsinha/Arm/ArmAndC/asmfunction.s:13:5: error: invalid operand for instruction add r0, r0, r1 ^ /Users/prokashsinha/Arm/ArmAndC/asmfunction.s:15:1: error: unrecognized instruction mnemonic, did you mean: b, bcax, bl, br, sb, tbx? bx lr ^ /Users/prokashsinha/Arm/ArmAndC/asmfunction.s:17:1: error: unknown directive .fnend ^
Posted
by
Post marked as solved
17 Replies
1.5k Views
I’m completely a newbie in the coding world. Been learning C++ for some days. I actually bought my MBA M1 to learn coding. But problems seem to appear whenever I tried to code #include . I use the latest Codelite as my IDE and when I hover towards the red arrow it says the following- error: no member named 'nullptr_t' in the global namespace I have tried this investigation provided by Eskimo - https://developer.apple.com/forums/thread/734833 But again the same errors keep occurring. As a complete newbie, I don’t know much things about these so any help would be amazing for me…. FYI I use the latest clang version as my command line tool and SIP is enabled. I tried restarting my Mac and tried multiple IDEs and code editors like vscode and nano etc. and macOS default terminal, but the the error kept the the same. Also running Ventura 13.3.1 …… Please provide me simply explained instructions to solve this annoying problem…..
Posted
by
Post not yet marked as solved
1 Replies
605 Views
Please tell me where I can find the documents for Apple Clang ARM assembler? After I compiled my C source code to ARM assembly code using Apple Clang, it of course generated a lot of ARM assembly code (GNU syntax), but for some of them I can't find related documents, for example the .build_version directive. The generated ARM assembly code is here: .section __TEXT,__text,regular,pure_instructions .build_version macos, 13, 0 sdk_version 13, 3 .globl _main ; -- Begin function main .p2align 2 _main: ; @main .cfi_startproc ; %bb.0: sub sp, sp, #64 str w8, [sp, #16] ; 4-byte Folded Spill stur wzr, [x29, #-4] ; implicit-def: $x8 ... add sp, sp, #64 ret .cfi_endproc ; -- End function .section __TEXT,__cstring,cstring_literals l_.str: ; @.str .asciz "a + b = %d\r\n" .subsections_via_symbols
Posted
by
Post marked as solved
2 Replies
556 Views
macOS flag is: -mmacosx-version-min=xx.yy iphoneos flag is: -mios-version-min=xx.yy iphonesimulator flag is: -mios-simulator-version-min=xx.yy but for xros things are going crazy .... xros flag -mtargetos=xrosxx.yy works well xrsimulator flag -mtargetos=xrosxx.yy or -mtargetos=xrsimulatorxx.yy are not working Does anyone no which is the right flag
Posted
by
Post not yet marked as solved
1 Replies
414 Views
Hi all, Our Objective-C project has quite a few Swift submodule that are linked with static Mach-O. The submodules are built and used in Objective-C files (.m, .mm) using the syntax #import <MyModule/MyModule-Swift.h> Since Xcode 14.3 and the early versions of Xcode 15.0, whenever I make any code changes in the .m .mm files (even just a space), all files using the Swift submodules are rebuilt. During my checks, I noticed the generated header of the submodules (MyModule-Swift.h) is regenerated even when its content hasn't changed. The modification time of the header file leads to the rebuilding of all Objective-C files. Of course, our project has a clean build when importing *-Swift.h in the .pch file, sometimes errors are thrown due to header changes during the build process. This behavior was not present in Xcode 14.2. More info I've tried configuring some flags in the Build settings, but they didn't work. Does anyone have any solutions to suggest for fixing this issue and saving our project ? :( Thanks!
Post not yet marked as solved
0 Replies
610 Views
Hi, I am running Mac Intel I7 post 2020 with Sonoma and clang 15.0 . The Clang 15.0 makes c++ code running 5 times slower than it was before upgrade from Ventura 13.6 and Clang 14.3.1 The other trouble is that Sonoma does not allow to revert to Clang 14.3.1 . I do not use Xcode only command line tools . here my options : g++ -std=c++17 -Ofast -march=native -funroll-loops -flto -DNDEBUG -o a prog.cpp So what happened to C++ ?
Posted
by
Post not yet marked as solved
3 Replies
1.1k Views
Has MACOSX_DEPLOYMENT_TARGET been deprecated? I do not seem to find any proper documentation of it at apple.com. Background: I'm building C-based application(s) and libraries (both Intel and AS) that are distributed compiled/linked to our users. I would like to update my build machines from 10.15 (Intel) and 11 (AS), to macOS 12 (or even higher, if possible) but I would like to be sure that our users can run the executable and that they can link their code against our libraries (and our object code) also on older versions of macOS. Ideally I would like to continue to support users on macOS 10.15 on Intel and 11 on AS, but macOS 11 on Intel would also be acceptable. It seems MACOSX_DEPLOYMENT_TARGET (perhaps combined with SDKROOT) could allow this, but I have not been able to find anything except rumors, i.e. no proper documentation at any Apple site. Testing is not really an option since at least some problems would likely only occur at runtime (e.g. due to weak linking). I am using the command line tools and GNU make (no Xcode project or some such, also no App Store). Any pointers would be greatly appreciated!
Posted
by
Post not yet marked as solved
1 Replies
316 Views
You can still use some xcode that is no longer supported on the desktop through the terminal. For example, my mocOS is 14.0, I installed xcode14 and xcode15 in /Applications, but xcode14 is no longer supported on the desktop. /Applications/Xcode_14.0.app # not supported /Applications/Xcode_15.0.app Switch to xcode14 and use xcodebuild: export DEVELOPER_DIR=/Applications/Xcode_14.0.app xcodebuild -version # work well I want to know if there is any problem with this approach? What does the Xcode development team think of this approach? Is there any relevant documentation that I can know about?
Posted
by
Post not yet marked as solved
1 Replies
899 Views
I'm trying to build C project with XCode 15.0, but always get error 'assert.h' file not found. I tried to clean and restart XCode, reinstall XCode and reboot, set different framework versions and project formats. I found all entries of stdarg.h with Finder and made sure, that all directories, containing stdarg.h, contain also assert.h, but stdarg.h includes are resolved, assert.h - not. How could this be ? Many thanks for any help. Ventura 13.6, M2, Command line tools version 2397
Posted
by
Post not yet marked as solved
0 Replies
588 Views
I just started getting lots of "redefinition of" errors with headers that start with #pragma once. The C++ clang compiler is set to "C++17". Did something change with handling #pragma?
Posted
by
Post not yet marked as solved
1 Replies
535 Views
Does this exist? Apple seems to have a unique syntax it recognizes (vs GCC arm64 assembler) and getting assembly code cross compiled it for iOS in Xcode has been very frustrating and unfruitful. Is there any guidance on how to do this? The reason for assembly is to support "volk, vector optimized library".
Posted
by
Post not yet marked as solved
0 Replies
466 Views
The project previously compiled using XCode 14.3, but I'm now having issues on XCode 15. It cannot find one of the header files that's used in one of my own lib that's associated to the project as a pod. // custom class imported from my other lib #import "fireBaseIntegration.h" Error: 'fireBaseIntegration.h' file not found
Posted
by