Mac应用程序将文件放在哪里?

时间:2020-09-19 19:32:42

标签: macos resources clang

我有一个使用clang和make构建的Mac应用程序。它需要一堆我的makefile放入foo.app/Contents/Resources中的资源文件,但是当我从Finder打开应用程序时,它找不到这些文件。假设我要读取的文件是foo.app/Contents/Resources/myfile;像ifstream(myfile)这样的调用失败(至少,流报告is_open == false)。

我对filesystem :: current_path()进行了调用,并报告它位于应用程序所在的目录中。可以肯定的是,如果我将foo.app/Contents/Resources/放在myfile的前面,ifstream(“ foo.app/Contents/Resources/myfile”)会找到它并打开它。

但这不是应该的工作方式。谁能告诉我我在做什么错?谢谢!

如果有帮助,我的Makefile:

CC = clang++

CFLAGS = -g -O3 -std=c++11 -Wall -Wno-c++11-extensions
# CFLAGS = -g -std=c++11 -Wall -Wno-c++11-extensions -fsanitize=address
# CFLAGS = -g -std=c++11 -Wall -Wno-c++11-extensions

TARGET = nfl

SRCS = nfl.cpp
OTHER_SRCS = actions.cpp info.cpp io.cpp model.cpp

OBJS = $(SRCS:.cpp=.o)
OTHER_OBJS = $(OTHER_SRCS:.cpp=.o)

WX_CONFIG = ./wx-config

NFL_VERSION = 0.1

CXX_EXTRA = -mmacosx-version-min=10.9 `$(WX_CONFIG) --cxxflags` -DWX_PRECOMP
LINK_EXTRA = -mmacosx-version-min=10.9 `$(WX_CONFIG) --libs` -lm

$(TARGET): $(OBJS) $(OTHER_OBJS)
       $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(OTHER_OBJS) $(LINK_EXTRA)

convert: convert.o io.o
    $(CC) $(CFLAGS) -o convert convert.o io.o

%.o:
    $(CC) $(CFLAGS) $(CXX_EXTRA) -c $< 

app:
    mkdir -p nfl.app/Contents
    mkdir -p nfl.app/Contents/MacOS
    mkdir -p nfl.app/Contents/Resources
    sed -e "s/VERSION/$(NFL_VERSION)/" \
    Info.plist.in >nfl.app/Contents/Info.plist
    echo -n "APPL????" >nfl.app/Contents/PkgInfo
    cp nfl nfl.app/Contents/MacOS/nfl
    cp -f wxmac.icns nfl.app/Contents/Resources/wxmac.icns
    cp -f full.csv nfl.app/Contents/Resources
    cp -f detailed_model nfl.app/Contents/Resources
    cp -f elapsed_model nfl.app/Contents/Resources

app:  nfl Info.plist.in wxmac.icns

deps: 
    $(CC) $(CFLAGS) $(CXX_EXTRA) -MM $(SRCS) $(OTHER_SRCS)

clean:  
    rm -f $(TARGET) *.o

convert.o: convert.cpp data.h
model.o: model.cpp data.h
io.o: io.cpp data.h

nfl.o: nfl.cpp nfl.h data.h
actions.o: actions.cpp nfl.h data.h
info.o: info.cpp nfl.h data.h

和我的Info.plist.in文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleIdentifier</key>
    <string>mattginsberg.com</string>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleExecutable</key>
    <string>nfl</string>
    <key>CFBundleIconFile</key>
    <string>wxmac.icns</string>
    <key>CFBundleName</key>
    <string>nfl</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>VERSION</string>
    <key>CFBundleShortVersionString</key>
    <string>VERSION</string>
    <key>NSHumanReadableCopyright</key>
    <string>Copyright (c) 2020 Matthew Ginsberg LLC.</string>
    <key>CSResourcesFileMapped</key>
    <true/>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
</dict>
</plist>

我使用--enable-debug --disable-shared构建了wxWidgets。

0 个答案:

没有答案
相关问题