Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ld:未找到架构x86_64 qt的符号_C++_Macos_Qt - Fatal编程技术网

C++ ld:未找到架构x86_64 qt的符号

C++ ld:未找到架构x86_64 qt的符号,c++,macos,qt,C++,Macos,Qt,我正在尝试编译一个基本的Qt程序: #include <iostream> #include <QApplication> int main(int argc, char** argv) { QApplication app(argc, argv); std::cout << "test" << std::endl; } 运行qmake命令 在生成的Makefile中编辑以下内容: -CXXFLAGS中的mmacosx版本最

我正在尝试编译一个基本的Qt程序:

#include <iostream>
#include <QApplication>

int main(int argc, char** argv) {
    QApplication app(argc, argv);

    std::cout << "test" << std::endl;
}
  • 运行
    qmake
    命令
  • 在生成的Makefile中编辑以下内容:
    • -CXXFLAGS中的mmacosx版本最小值=10.15.3
    • 从编译器中删除-c参数
  • 然后我运行了
    make
    ,得到了以下错误输出:
  • 我可能知道这是什么原因,当运行
    make-v
    时,我得到以下输出:

    This program built for i386-apple-darwin11.3.0
    
    Apple clang version 11.0.0 (clang-1100.0.33.16)
    Target: x86_64-apple-darwin19.3.0
    Thread model: posix
    
    clang++--version
    生成此输出:

    This program built for i386-apple-darwin11.3.0
    
    Apple clang version 11.0.0 (clang-1100.0.33.16)
    Target: x86_64-apple-darwin19.3.0
    Thread model: posix
    
    我认为Makefile试图为旧的体系结构编译代码,这会产生冲突,但我不确定。我的系统是运行MacOS Catalina 10.15.3的Macbook Pro。Qt是15.4.1版。Qmake是3.1版

    完整生成文件:

    #############################################################################
    # Makefile for building: test.app/Contents/MacOS/test
    # Generated by qmake (3.1) (Qt 5.14.1)
    # Project:  test.pro
    # Template: app
    # Command: /usr/local/Cellar/qt/5.14.1/bin/qmake -o Makefile test.pro
    #############################################################################
    
    MAKEFILE      = Makefile
    
    EQ            = =
    
    ####### Compiler, tools and options
    
    CC            = /Library/Developer/CommandLineTools/usr/bin/clang
    CXX           = /Library/Developer/CommandLineTools/usr/bin/clang++
    DEFINES       = -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB
    CFLAGS        = -pipe -O2 $(EXPORT_ARCH_ARGS) -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wall -Wextra -fPIC $(DEFINES)
    CXXFLAGS      = -pipe -stdlib=libc++ -O2 -std=gnu++11 $(EXPORT_ARCH_ARGS) -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.15.3 -Wall -Wextra -fPIC $(DEFINES)
    INCPATH       = -I. -I/usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Headers -I/usr/local/Cellar/qt/5.14.1/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.14.1/lib/QtCore.framework/Headers -I. -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.14.1/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.14.1/lib
    QMAKE         = /usr/local/Cellar/qt/5.14.1/bin/qmake
    DEL_FILE      = rm -f
    CHK_DIR_EXISTS= test -d
    MKDIR         = mkdir -p
    COPY          = cp -f
    COPY_FILE     = cp -f
    COPY_DIR      = cp -f -R
    INSTALL_FILE  = install -m 644 -p
    INSTALL_PROGRAM = install -m 755 -p
    INSTALL_DIR   = cp -f -R
    QINSTALL      = /usr/local/Cellar/qt/5.14.1/bin/qmake -install qinstall
    QINSTALL_PROGRAM = /usr/local/Cellar/qt/5.14.1/bin/qmake -install qinstall -exe
    DEL_FILE      = rm -f
    SYMLINK       = ln -f -s
    DEL_DIR       = rmdir
    MOVE          = mv -f
    TAR           = tar -cf
    COMPRESS      = gzip -9f
    DISTNAME      = test1.0.0
    DISTDIR = /Users/myName/School/C++/QtTest/.tmp/test1.0.0
    LINK          = /Library/Developer/CommandLineTools/usr/bin/clang++
    LFLAGS        = -stdlib=libc++ -headerpad_max_install_names $(EXPORT_ARCH_ARGS) -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wl,-rpath,@executable_path/../Frameworks
    LIBS          = $(SUBLIBS) -F/usr/local/Cellar/qt/5.14.1/lib -framework QtWidgets -framework QtGui -framework AppKit -framework Metal -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL   
    AR            = /Library/Developer/CommandLineTools/usr/bin/ar cq
    RANLIB        = /Library/Developer/CommandLineTools/usr/bin/ranlib -s
    SED           = sed
    STRIP         = strip
    
    ####### Output directory
    
    OBJECTS_DIR   = ./
    
    ####### Files
    
    SOURCES       = main.cpp 
    OBJECTS       = main.o
    DIST          = /usr/local/Cellar/qt/5.14.1/mkspecs/features/spec_pre.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/qdevice.pri \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/device_config.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/common/unix.conf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/common/mac.conf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/mac/rez.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/mac/asset_catalogs.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/testcase_targets.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/exceptions.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/yacc.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/lex.prf \
    
            MORE FILES HERE
    
            test.pro  main.cpp
    QMAKE_TARGET  = test
    DESTDIR       = 
    TARGET        = test.app/Contents/MacOS/test
    
    ####### Custom Variables
    EXPORT_QMAKE_MAC_SDK = macosx
    EXPORT_QMAKE_MAC_SDK_VERSION = 10.15.1
    EXPORT_QMAKE_XCODE_DEVELOPER_PATH = /Library/Developer/CommandLineTools
    EXPORT_VALID_ARCHS = x86_64
    EXPORT_ACTIVE_ARCHS = $(filter $(EXPORT_VALID_ARCHS), $(ARCHS))
    EXPORT_ARCH_ARGS = $(foreach arch, $(if $(EXPORT_ACTIVE_ARCHS), $(EXPORT_ACTIVE_ARCHS), $(EXPORT_VALID_ARCHS)), -arch $(arch))
    EXPORT__PRO_FILE_ = /Users/myName/School/C++/QtTest/test.pro
    
    
    include /usr/local/Cellar/qt/5.14.1/mkspecs/features/mac/sdk.mk
    first: all
    ####### Build rules
    
    test.app/Contents/MacOS/test:  $(OBJECTS)  
        @test -d test.app/Contents/MacOS/ || mkdir -p test.app/Contents/MacOS/
        $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
    
    Makefile: test.pro /usr/local/Cellar/qt/5.14.1/mkspecs/macx-clang/qmake.conf /usr/local/Cellar/qt/5.14.1/mkspecs/features/spec_pre.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/qdevice.pri \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/device_config.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/common/unix.conf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/exceptions.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/yacc.prf \
            /usr/local/Cellar/qt/5.14.1/mkspecs/features/lex.prf \
            test.pro \
            /usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Resources/QtWidgets.prl \
            /usr/local/Cellar/qt/5.14.1/lib/QtGui.framework/Resources/QtGui.prl \
            /usr/local/Cellar/qt/5.14.1/lib/QtCore.framework/Resources/QtCore.prl
    
            MORE FILES HERE
    
        $(QMAKE) -o Makefile test.pro
    /usr/local/Cellar/qt/5.14.1/mkspecs/features/spec_pre.prf:
    /usr/local/Cellar/qt/5.14.1/mkspecs/qdevice.pri:
    /usr/local/Cellar/qt/5.14.1/mkspecs/features/device_config.prf:
    /usr/local/Cellar/qt/5.14.1/mkspecs/common/unix.conf:
    /usr/local/Cellar/qt/5.14.1/mkspecs/common/mac.conf:
    /usr/local/Cellar/qt/5.14.1/mkspecs/features/lex.prf:
    test.pro:
    /usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Resources/QtWidgets.prl:
    /usr/local/Cellar/qt/5.14.1/lib/QtGui.framework/Resources/QtGui.prl:
    /usr/local/Cellar/qt/5.14.1/lib/QtCore.framework/Resources/QtCore.prl:
    
    MORE FILES HERE
    
    qmake: FORCE
        @$(QMAKE) -o Makefile test.pro
    
    qmake_all: FORCE
    
    test.app/Contents/PkgInfo: 
        @test -d test.app/Contents || mkdir -p test.app/Contents
        @$(DEL_FILE) test.app/Contents/PkgInfo
        @echo "APPL????" > test.app/Contents/PkgInfo
    test.app/Contents/Resources/empty.lproj: 
        @test -d test.app/Contents/Resources || mkdir -p test.app/Contents/Resources
        @touch test.app/Contents/Resources/empty.lproj
    
    test.app/Contents/Info.plist: 
        @test -d test.app/Contents || mkdir -p test.app/Contents
        @$(DEL_FILE) test.app/Contents/Info.plist
        @sed -e "s,@SHORT_VERSION@,1.0,g" -e "s,\$${QMAKE_SHORT_VERSION},1.0,g" -e "s,@FULL_VERSION@,1.0.0,g" -e "s,\$${QMAKE_FULL_VERSION},1.0.0,g" -e "s,@TYPEINFO@,????,g" -e "s,\$${QMAKE_PKGINFO_TYPEINFO},????,g" -e "s,@BUNDLEIDENTIFIER@,com.yourcompany.test,g" -e "s,\$${PRODUCT_BUNDLE_IDENTIFIER},com.yourcompany.test,g" -e "s,\$${MACOSX_DEPLOYMENT_TARGET},10.13,g" -e "s,\$${IPHONEOS_DEPLOYMENT_TARGET},,g" -e "s,\$${TVOS_DEPLOYMENT_TARGET},,g" -e "s,\$${WATCHOS_DEPLOYMENT_TARGET},,g" -e "s,@ICON@,,g" -e "s,\$${ASSETCATALOG_COMPILER_APPICON_NAME},,g" -e "s,@EXECUTABLE@,test,g" -e "s,@LIBRARY@,test,g" -e "s,\$${EXECUTABLE_NAME},test,g" -e "s,@TYPEINFO@,????,g" -e "s,\$${QMAKE_PKGINFO_TYPEINFO},????,g" /usr/local/Cellar/qt/5.14.1/mkspecs/macx-clang/Info.plist.app >test.app/Contents/Info.plist
    
    all: Makefile \
            test.app/Contents/PkgInfo \
            test.app/Contents/Resources/empty.lproj \
            test.app/Contents/Info.plist test.app/Contents/MacOS/test
    
    dist: distdir FORCE
        (cd `dirname $(DISTDIR)` && $(TAR) $(DISTNAME).tar $(DISTNAME) && $(COMPRESS) $(DISTNAME).tar) && $(MOVE) `dirname $(DISTDIR)`/$(DISTNAME).tar.gz . && $(DEL_FILE) -r $(DISTDIR)
    
    distdir: FORCE
        @test -d $(DISTDIR) || mkdir -p $(DISTDIR)
        $(COPY_FILE) --parents $(DIST) $(DISTDIR)/
        $(COPY_FILE) --parents /usr/local/Cellar/qt/5.14.1/mkspecs/features/data/dummy.cpp $(DISTDIR)/
        $(COPY_FILE) --parents main.cpp $(DISTDIR)/
    
    
    clean: compiler_clean 
        -$(DEL_FILE) $(OBJECTS)
        -$(DEL_FILE) *~ core *.core
    
    
    distclean: clean 
        -$(DEL_FILE) -r test.app
        -$(DEL_FILE) .qmake.stash
        -$(DEL_FILE) Makefile
    
    
    ####### Sub-libraries
    
    xcodeproj:
        @$(QMAKE) -spec macx-xcode "$(EXPORT__PRO_FILE_)"
    
    mocclean: compiler_moc_header_clean compiler_moc_objc_header_clean compiler_moc_source_clean
    
    mocables: compiler_moc_header_make_all compiler_moc_objc_header_make_all compiler_moc_source_make_all
    
    check: first
    
    benchmark: first
    
    compiler_rcc_make_all:
    compiler_rcc_clean:
    compiler_moc_predefs_make_all: moc_predefs.h
    compiler_moc_predefs_clean:
        -$(DEL_FILE) moc_predefs.h
    moc_predefs.h: /usr/local/Cellar/qt/5.14.1/mkspecs/features/data/dummy.cpp
        /Library/Developer/CommandLineTools/usr/bin/clang++ -pipe -stdlib=libc++ -O2 -std=gnu++11 $(EXPORT_ARCH_ARGS) -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wall -Wextra -dM -E -o moc_predefs.h /usr/local/Cellar/qt/5.14.1/mkspecs/features/data/dummy.cpp
    
    compiler_moc_header_make_all:
    compiler_moc_header_clean:
    compiler_moc_objc_header_make_all:
    compiler_moc_objc_header_clean:
    compiler_moc_source_make_all:
    compiler_moc_source_clean:
    compiler_uic_make_all:
    compiler_uic_clean:
    compiler_rez_source_make_all:
    compiler_rez_source_clean:
    compiler_yacc_decl_make_all:
    compiler_yacc_decl_clean:
    compiler_yacc_impl_make_all:
    compiler_yacc_impl_clean:
    compiler_lex_make_all:
    compiler_lex_clean:
    compiler_clean: compiler_moc_predefs_clean 
    
    ####### Compile
    
    main.o: main.cpp /usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Headers/QApplication \
            /usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Headers/qapplication.h
        $(CXX) $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
    
    ####### Install
    
    install:  FORCE
    
    uninstall:  FORCE
    
    FORCE:
    
    
    

    谢谢

    我犯了一个非常基本的错误。一切正常,但Makefile输出了一个
    main.o
    文件。我试图使用
    /main.o
    执行我的应用程序。这是不可能的

    执行Qt应用程序的正确方法是使用
    openmain.app

    无需更改makefile

  • 创建myApp.pro文件 例如:
  • 执行
    qmake
  • 执行
    make
  • 执行
    打开myApp.app

  • 为什么要处理创建的Makefile?如果不更改生成文件,会发生什么?@FrankOsterfeld如果我不更改生成文件,我的代码编译得很好,但由于“exec格式错误”,我无法运行它::。并检查cflags和CxFlags-有不一致之处。@RichardBarber您能详细说明一下吗?我到底应该做些什么来保持一致?当我用C++编译时(CXFLAGS)对我来说是什么重要的,但是我对你的设置有一些不同:MaOS101.6;我使用的是完整的Xcode安装,而您似乎只安装了CommandLineTools。另外,我使用的是来自官方Qt安装程序的软件包,而不是自制的。省略
    -c
    显然是错误的(这是关于构建main.o,而不是链接二进制文件)。什么时候出现执行格式错误?在
    open project.app
    上,还是在
    project.app/Contents/MacOS/project
    上?
    TEMPLATE += app
    QT += widgets gui
    SOURCES += myApp.cpp