You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除CMake中所有默认编译器选项以适配CC65

问题描述

我正尝试让CC65编译器与CMake配合工作,以便在CLion中开展项目。目前已实现CMake调用正确的编译器,但CMake仍会添加大量我不需要的GNU风格编译器选项:

Compiler exited with error code 1: /opt/local/bin/cc65 -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E
cc65: Unknown option: -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END

如何移除所有默认选项,让我可以从零开始逐步构建正确的选项?


更新1

我使用的工具链文件并非自行开发,结构较为简单。


更新2

我并非手动调用CMake,只是为了使用JetBrains CLion才进行这些操作。如果不是为了CLion,我只会使用GNU-Make。由于无法手动调用CMake,命令行选项不适用,因此我使用set()函数:

set (CMAKE_TOOLCHAIN_FILE "${PROJECT_SOURCE_DIR}/Library/CMake/Atari/cc65-toolchain.cmake")

完整输出如下:

/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/opt/local/bin/gmake -DCMAKE_C_COMPILER=/opt/local/bin/cc65 -G "CodeBlocks - Unix Makefiles" -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-debug-c65
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cc65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-debug-c65

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END
    
    

[Previous CMake output restored: 17.10.22, 17:40]

我已提供完整CMakeLists.txt文件。


更新3

为了确认是否能修改CLion生成的命令,我进行了尝试,输出略有不同但结果一致:

/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/opt/local/bin/gmake -DCMAKE_C_COMPILER=/opt/local/bin/cc65 --toolchain Library/CMake/Atari/cc65-toolchain.cmake -G "CodeBlocks - Unix Makefiles" -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release-c65
>>cc65-toolchain.cmake
>>cc65-toolchain.cmake
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/ca65
-- Detecting C compiler ABI info
>>cc65-toolchain.cmake
-- Detecting C compiler ABI info - failed
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cc65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release-c65

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END

更新4

切换到CLion默认工具链配置以排查是否存在冲突,但结果是所有选项以DOS风格(用'/'替代'-')传递:

/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/ninja/mac/ninja --toolchain Library/CMake/Atari/cc65-toolchain.cmake -G Ninja -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release
>>cc65-toolchain.cmake
>>cc65-toolchain.cmake
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/ca65
-- Detecting C compiler ABI info
>>cc65-toolchain.cmake
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/local/bin/cl65 - skipped
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cl65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cl65 @/private/var/folders/yv/kps0l5k55db3bmvbp4mbcdpw0000gn/T/response-file5391882336445539336 /private/var/folders/yv/kps0l5k55db3bmvbp4mbcdpw0000gn/T/compiler-file6838441381382142237 | @response-file5391882336445539336=/TC -t atari /Be /Bd /EP
    cl65: Don't know what to do with '/TC -t atari /Be /Bd /EP'

内容的提问来源于stack exchange,提问作者Martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:55:18