简体   繁体   中英

ld: symbol(s) not found for architecture x86_64 qt

I'm trying to compile a basic Qt program:

#include <iostream>
#include <QApplication>

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

    std::cout << "test" << std::endl;
}

To start a Qt-project I did the following:

  1. Make a project.pro file:
TEMPLATE += app
QT += widgets gui
SOURCES += main.cpp
  1. Run the qmake command.
  2. Edit the following in the generated Makefile:
    • -mmacosx-version-min=10.15.3 in CXXFLAGS
    • remove the -c argument from the compiler
  3. Than I ran make and got the following error output:
/Library/Developer/CommandLineTools/usr/bin/clang++ -pipe -stdlib=libc++ -O2 -std=gnu++11  -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.15.3 -Wall -Wextra -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -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 -o main.o main.cpp
Undefined symbols for architecture x86_64:
  "QApplication::QApplication(int&, char**, int)", referenced from:
      _main in main-96fd09.o
  "QApplication::~QApplication()", referenced from:
      _main in main-96fd09.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main.o] Error 1

I might have an idea what is causing this, when running make -v I get this output:

This program built for i386-apple-darwin11.3.0

clang++ --version generates this output:

Apple clang version 11.0.0 (clang-1100.0.33.16)
Target: x86_64-apple-darwin19.3.0
Thread model: posix

I think the Makefile is trying to compile my code for an older architecture and that's generating a conflict but I'm not sure. My system is a Macbook Pro running MacOS Catalina 10.15.3. Qt is version 15.4.1. Qmake is version 3.1.

Full Makefile:

#############################################################################
# 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:


Thanks!

I made a very basic mistake. Everything was working, but the Makefile outputted a main.o file. I tried to execute my application by using ./main.o . This is not possible.

The correct way to execute a Qt application is by using open main.app .

No need to alter the makefile.

  1. Create a myApp.pro file Example:
TEMPLATE += app
QT += widgets gui
SOURCES += myApp.cpp
  1. Execute qmake
  2. Execute make
  3. Execute open myApp.app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM