gpt4 book ai didi

objective-c - Linux 上使用 Cocoa 的 Objective-C 的 Makefile 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:27 25 4
gpt4 key购买 nike

我正在尝试编写一个 makefile 以在 Linux 上使用 Cocoa 编译 Objective-C。

我已经安装了以下软件包:

sudo apt-get install gnustep gnustep-devel

我从一个最小的 makefile 开始,它编译成功:

FLAGS = $(shell gnustep-config --objc-flags)
LIBS = $(shell gnustep-config --base-libs)

all:
gcc $(FLAGS) HelloWorld.m $(LIBS) -o a.out

这是唯一的源文件:

#include <Foundation/Foundation.h>

int main(int argc, const char* argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello, World!");

[pool drain];
return 0;
}

现在我正在尝试编写一个更详细的 makefile,但我还不能让它工作:

CC = gcc
SOURCES=HelloWorld.m
OBJECTS=$(SOURCES:.m=.o)
CFLAGS=-c $(shell gnustep-config --objc-flags)
LIBRARIES = $(shell gnustep-config --base-libs)
FRAMEWORKS:= -framework Foundation -framework Cocoa -framework AppKit
LDFLAGS=$(LIBRARIES) $(FRAMEWORKS)
EXECUTABLE=a.out

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.m.o:
$(CC) $(CFLAGS) $(LIBRARIES) $< -o $@

输出:

$ make
gcc -rdynamic -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -shared-libgcc -shared-libgcc -pthread -fexceptions -fgnu-runtime -L/home/brett/GNUstep/Library/Libraries -L/usr/local/lib -L/usr/lib -lgnustep-base -lobjc -lm -framework Foundation -framework Cocoa -framework AppKit HelloWorld.o -o a.out
gcc: error: Foundation: No such file or directory
gcc: error: Cocoa: No such file or directory
gcc: error: AppKit: No such file or directory
gcc: error: unrecognized command line option ‘-framework’
gcc: error: unrecognized command line option ‘-framework’
gcc: error: unrecognized command line option ‘-framework’
Makefile:14: recipe for target 'a.out' failed
make: *** [a.out] Error 1

海湾合作委员会版本:

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.2.0-8ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3) gnustep-config --base-libs


$ gnustep-config --objc-flags
-MMD -MP -Wdate-time -D_FORTIFY_SOURCE=2 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -O2 -fdebug-prefix-map=/build/gnustep-make-1owDvd/gnustep-make-2.6.8=. -fstack-protector-strong -Wformat -Werror=format-security -g -O2 -fdebug-prefix-map=/build/gnustep-make-1owDvd/gnustep-make-2.6.8=. -fstack-protector-strong -Wformat -Werror=format-security -fgnu-runtime -fconstant-string-class=NSConstantString -I. -I/home/brett/GNUstep/Library/Headers -I/usr/local/include/GNUstep -I/usr/include/GNUstep

$ gnustep-config --base-libs
-rdynamic -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -shared-libgcc -shared-libgcc -pthread -fexceptions -fgnu-runtime -L/home/brett/GNUstep/Library/Libraries -L/usr/local/lib -L/usr/lib -lgnustep-base -lobjc -lm
brett@brett-desktop:~/Git/Mandelbrot/Mandelbrot2$ gnustep-config --base-libsgnustep-config --base-libs

实际上我想我看到了问题,我的 gnustep-config --base-libs 输出 -L/home/brett/GNUstep/Library/Libraries 在我的环境中不存在。如果我弄清楚如何正确安装库,我会更新。

似乎 gnustep-devel 包只安装了文档:

$ dpkg-query -L gnustep-devel
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/gnustep-devel
/usr/share/doc/gnustep-devel/copyright
/usr/share/doc/gnustep-devel/changelog.gz

我在/usr/share/GNUstep 下找到了一些文件,但没有找到 Foundation.h:

$ find . -name *.h
./Makefiles/TestFramework/ObjectTesting.h
./Makefiles/TestFramework/Testing.h

最佳答案

你可能想试试这个:

CC = gcc
SOURCES=HelloWorld.m
OBJECTS=$(SOURCES:.m=.o)
CCFLAGS=`gnustep-config --objc-flags` -c
OBJCLIBS=`gnustep-config --objc-libs` -lgnustep-base

EXECUTABLE=a.out

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^ $(OBJCLIBS)

%.o : %.m
$(CC) $(CCFLAGS) -o $@ -c $<

我没有详细检查,但是在你的 makefile 中,所有“-I”指令都丢失了,如下所示:

-I/usr/local/include/GNUstep -I/usr/include/GNUstep

关于objective-c - Linux 上使用 Cocoa 的 Objective-C 的 Makefile 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47620964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com