May 5, 2011

calumcjr calumcjr
Ant Farmer
3 posts

[Moved] symbol(s) not found for architecture x86_64

 

Hi,

I’m using Qt Creator 2.1.0 (based on Qt 4.7.1 64 bit) on my Apple Mac, and I’ve run into a build problem when trying to reference symbol EVP_sha1() which resides in libssl.dylib. I get the following error:

  1. Undefined symbols for architecture x86_64:
  2.   "_EVP_sha1", referenced from:
  3. make: Leaving directory `/Users/cjr/Documents/development/qt/TestSSL-build-desktop'

In my .pro file, I have the line:

  1. LIBS += -L/usr/lib -lssl

and my code is:

  1. #include <QtCore/QCoreApplication>
  2. #include <openssl/sha.h>
  3. #include <openssl/hmac.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     QCoreApplication a(argc, argv);
  8.  
  9.     unsigned char *key      = (unsigned char *)"MySecretKey";
  10.     unsigned char *message  = (unsigned char *)"FakeRequestDescription";
  11.     unsigned char out[30];
  12.     unsigned int len = 0;
  13.  
  14.     HMAC(EVP_sha1(),
  15.          key,
  16.          11,
  17.          message,
  18.          22,
  19.          out,
  20.          &len);
  21.  
  22.     return a.exec();
  23. }

Using nm on the libssl.dylib shows the following output:

  1. MacBook-Pro:lib cjr$ file libssl.dylib
  2. libssl.dylib: Mach-O universal binary with 3 architectures
  3. libssl.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
  4. libssl.dylib (for architecture i386): Mach-O dynamically linked shared library i386
  5. libssl.dylib (for architecture ppc7400): Mach-O dynamically linked shared library ppc

Does anyone have any ideas on what I can do to get this working?

Thanks.

15 replies

May 5, 2011

Volker Volker
Ant Farmer
5331 posts

Which OS X SDK are you compiling against?
If it is 10.4u, this does not contain 64bit symbols (and I think it’s actually linked against /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/libssl.dylib then)

May 6, 2011

calumcjr calumcjr
Ant Farmer
3 posts

Hi there,

Thanks for the reply. I’m using the 10.6 OS X SDK. I’ve also just tried explicitly linking like this, to no avail:

  1. LIBS += /Developer/SDKs/MacOSX10.6.sdk/usr/lib/libssl.dylib

May 6, 2011

Volker Volker
Ant Farmer
5331 posts

Very strange. It works for me:

  1. LIBS += -lssl -lcrypto

No additional paths (/usr/lib is in the list anyways) and with pure x86_64 build (no i386, no ppc). Can you upload /usr/lib/libssl.dylib (resp. the file that symlink points to) somewhere? I’ll have a look at it and will compare it against that in my system (OS X 10.6.7).

Ah, and can you post the output of the compilation, please. I’d like to know how the compiler is acutally called.

I moved this thread to the Tools forum, as it’s not Qt related.

May 6, 2011

calumcjr calumcjr
Ant Farmer
3 posts

Thanks for your help.

I’ve placed the file here [dl.dropbox.com].

Unsure if it is important but the version of the library in /usr/lib is larger than the one in /Developer/SDKs/MacOSX10.6.sdk/usr/lib

The output of the compilation is as follows:

Running build steps for project TestSSL…
Configuration unchanged, skipping qmake step.
Starting: “/usr/bin/make” -w
make: Entering directory `/Users/cjr/Documents/development/qt/TestSSL-build-desktop’
g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_CORE_LIB -I../../../../QtSDK/Desktop/Qt/473/gcc/mkspecs/macx-g++ -I../TestSSL -I../../../../QtSDK/Desktop/Qt/473/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../../QtSDK/Desktop/Qt/473/gcc/include/QtCore -I../../../../QtSDK/Desktop/Qt/473/gcc/include -I. -I../TestSSL -I. -F/Users/cjr/QtSDK/Desktop/Qt/473/gcc/lib -o main.o ../TestSSL/main.cpp
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o TestSSL main.o -F/Users/cjr/QtSDK/Desktop/Qt/473/gcc/lib -L/Users/cjr/QtSDK/Desktop/Qt/473/gcc/lib /Developer/SDKs/MacOSX10.6.sdk/usr/lib/libssl.dylib -framework QtCore
Undefined symbols for architecture x86_64: “_EVP_sha1”, referenced from:
make: Leaving directory `/Users/cjr/Documents/development/qt/TestSSL-build-desktop’ _main in main.o “_HMAC”, referenced from: _main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [TestSSL] Error 1
The process “/usr/bin/make” exited with code 2.
Error while building project TestSSL (target: Desktop)
When executing build step ‘Make’

May 6, 2011

Volker Volker
Ant Farmer
5331 posts

Ok, found the error. The files are identical (bitwise), so no need to worry about this. You seem to have in your .pro something like this:

  1. LIBS += /Developer/SDKs/MacOSX10.6.sdk/usr/lib/libssl.dylib

This is wrong. The files in the SDKs subdirs are only library stubs, the do not contain actual code (so we found the reason why they’re smaller than those in /usr/lib).

Please replace the line above by

  1. LIBS += -lssl -lcrypto

And have a look if you have other references to that SDK dir, other than

  1. QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.6.sdk

If you do have, please remove them too.

This is a complete small project that works for me:

——— test.pro ———

  1. QT -= core
  2. TARGET = SimpleConsoleTest
  3. CONFIG += console
  4. CONFIG -= app_bundle
  5. CONFIG += x86_64
  6. CONFIG -= i386
  7. TEMPLATE = app
  8. LIBS += -lssl -lcrypto
  9. SOURCES += main.cpp

——— main.cpp ———

  1. #include <QtCore/QCoreApplication>
  2. #include <QtCore/QDebug>
  3. #include <openssl/sha.h>
  4. #include <openssl/hmac.h>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.     QCoreApplication a(argc, argv);
  9.  
  10.     unsigned char *key      = (unsigned char *)"MySecretKey";
  11.     unsigned char *message  = (unsigned char *)"FakeRequestDescription";
  12.     unsigned char out[30];
  13.     unsigned int len = 0;
  14.  
  15.     qDebug() << "key:" << (char*)key;
  16.     qDebug() << "msg:" << (char*)message;
  17.  
  18.     HMAC(EVP_sha1(),
  19.          key,
  20.          11,
  21.          message,
  22.          22,
  23.          out,
  24.          &len);
  25.  
  26.     qDebug() << "out:" << (char*)out;
  27.  
  28.     return 0;
  29. }

May 6, 2011

calumcjr calumcjr
Ant Farmer
3 posts

Thanks Volker, that did the trick. It was because I was missing -lcrypto from the LIBS line.

June 17, 2011

thisaintme thisaintme
Lab Rat
5 posts

Hi,

for some reason I’m having the same problem as calumcjr. I’m using Qt 4.7.3 on my Mac (OS X.6.7).
I tried to run my project from Qt Creator and from eclipse but I keep getting the above mentioned error message.

Background: I need to implement a few functionalities into a given framework that wasn’t created by myself.
As the framework is quite large, I think it’s not useful to post it here. And as the above mentioned problem could be solved by modifying the pro-file I think that’s where my problem might be as well.

So here’s my pro-file:

  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2011-06-17T13:45:15
  4. #
  5. #-------------------------------------------------
  6.  
  7. QT       += core gui
  8.  
  9. TARGET = Ueb03
  10. TEMPLATE = app
  11. DEPENDPATH += . src
  12. INCLUDEPATH += . src
  13. CONFIG -= app_bundle
  14. CONFIG += x86_64
  15. CONFIG -= i386
  16. LIBS += -lssl -lcrypto
  17.  
  18.  
  19. HEADERS += src/Geometry.h \
  20.            src/MainWindow.h \
  21.            src/Model.h \
  22.            src/MovingBox.h \
  23.            src/RollingBall.h \
  24.            src/RotatingCow.h \
  25.            src/RotationWidget.h
  26. SOURCES += src/Geometry.cpp \
  27.            src/main.cpp \
  28.            src/MainWindow.cpp \
  29.            src/Model.cpp \
  30.            src/MovingBox.cpp \
  31.            src/RollingBall.cpp \
  32.            src/RotatingCow.cpp \
  33.            src/RotationWidget.cpp

I made a few modifications according to the sampe pro file. Yet I get this error message:
error: symbol(s) not found for architecture x86_64

If you need any further information, please let me know.

Thanks a lot in advance.

June 19, 2011

Volker Volker
Ant Farmer
5331 posts

thisaintme, it’s not clear in what step and which object file the architecture is missing. Please check those with

  1. file name-of-file-or-lib

it should print out all the architectures that are contained in your file.

First start with the lib you are linking to. You must have the same architectures (or less), but no more additional ones in your project.

July 2, 2011

thisaintme thisaintme
Lab Rat
5 posts

Hi Volker,

here’s what I get when running the file-command:

  1. Geometry.o:           Mach-O 64-bit object x86_64
  2. MainWindow.o:         Mach-O 64-bit object x86_64
  3. Model.o:              Mach-O 64-bit object x86_64
  4. MovingBox.o:          Mach-O 64-bit object x86_64
  5. RollingBall.o:        Mach-O 64-bit object x86_64
  6. RotatingCow.o:        Mach-O 64-bit object x86_64
  7. RotationWidget.o:     Mach-O 64-bit object x86_64
  8. main.o:               Mach-O 64-bit object x86_64
  9. moc_MainWindow.o:     Mach-O 64-bit object x86_64
  10. moc_MovingBox.o:      Mach-O 64-bit object x86_64
  11. moc_RollingBall.o:    Mach-O 64-bit object x86_64
  12. moc_RotatingCow.o:    Mach-O 64-bit object x86_64
  13. moc_RotationWidget.o: Mach-O 64-bit object x86_64

So it looks like the linked objects all are x86_64.
Any idea, what the problem might be?

July 4, 2011

Volker Volker
Ant Farmer
5331 posts

Problem seems more to be on a lib that’s tried to be linked.

July 6, 2011

thisaintme thisaintme
Lab Rat
5 posts

In my makefile the libs-line looks like this:

  1. LIBS          = $(SUBLIBS) -F/Users/username/QtSDK/Simulator/Qt/gcc/lib -L/Users/username/QtSDK/Simulator/Qt/gcc/lib -framework QtGui -framework QtCore

I don’t know what $(SUBLIBS) stands for, but for the rest I think it should all be x86_64.
Anything else I should check?

July 6, 2011

Volker Volker
Ant Farmer
5331 posts

Best bet would be to look at the output of the compiler pane. It shows you the exact command line that is used for linking. You would have to check all of the libs on that.

July 6, 2011

thisaintme thisaintme
Lab Rat
5 posts

This is the output of the compiler pane:

  1. make: Entering directory `/Users/username/Documents/workspace/Qt/Ueb03-build-desktop'
  2. /Users/username/QtSDK/Desktop/Qt/473/gcc/bin/qmake -spec ../../../../QtSDK/Desktop/Qt/473/gcc/mkspecs/macx-g++
  3. <QMLJSDEBUGGER_PATH=/Users/username/QtSDK/Qt\ Creator.app/Contents/Resources/qml/qmljsdebugger -o Makefile ../Ueb03/Ueb03.pro

(End of part 1)

July 6, 2011

thisaintme thisaintme
Lab Rat
5 posts

(Part 2)

  1. make: Leaving directory `/Users/username/Documents/workspace/Qt/Ueb03-build-desktop'
  2. make: Entering directory `/Users/username/Documents/workspace/Qt/Ueb03-build-desktop'
  3. g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o Ueb03.app/Contents/MacOS/Ueb03 Geometry.o main.o MainWindow.o Model.o MovingBox.o RollingBall.o RotatingCow.o RotationWidget.o moc_MainWindow.o moc_MovingBox.o moc_RollingBall.o moc_RotatingCow.o moc_RotationWidget.o   -F/Users/username/QtSDK/Desktop/Qt/473/gcc/lib -L/Users/username/QtSDK/Desktop/Qt/473/gcc/lib -framework QtGui -framework QtCore

I don’t know exactly where linking part comes but I don’t see any files or libraries that are not x86_64…

July 6, 2011

Volker Volker
Ant Farmer
5331 posts

This should probably work. I cannot see the external framework that you link to.

I never installed the SDK version of the Qt libs, so I don’t know if those contain a x86_64 version. You might want to check the output of

  1. lipo -info /Users/username/QtSDK/Desktop/Qt/473/gcc/lib/QtGui.framework/QtGui
  2. lipo -info /Users/username/QtSDK/Desktop/Qt/473/gcc/lib/QtCore.framework/QtCore

it should contain x86_64

 
  ‹‹ QtCreator: How to load remaining dll:s in plugins/designer folder?      Force Qt Creator to use a syntax highlighting for a file ››

You must log in to post a reply. Not a member yet? Register here!