I try to build a simple Qt 5 program on Mac. But I failed.
The code is very simple:
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication app (argc, argv);
return app.exec();
}
I used:
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib test.cpp
Then I got this error:
Undefined symbols for architecture x86_64:
"QApplication::exec()", referenced from:
_main in test-jPGORy.o
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in test-jPGORy.o
"QApplication::~QApplication()", referenced from:
_main in test-jPGORy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there anything i missing?
Firstly, don't compile and link Qt projects by hand; use qmake and project files.
Run qmake -project in your source directory to generate a basic project file.
Edit the project file and add the following line: QT += widgets
Now run qmake to generate a makefile.
Now run make to build your program.
Secondly, you can simply #include <QApplication>
If you want to use clang++ in favor of qmake, you need to specify libraries to link against to, along with the library directory (which you supplied).
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib -lQtCore -lQtGui test.cpp
I had the same problems and it seems to me that there is some sort of bug in the release it gave me some errors because out of a fresh install (using qt creator) i didn't have some obscure qt library (not the normal qt5 modules but some sort of library in development) so I tend to think that it could be qt's problem
That said I have some questions to better understand:
-are you using a IDE?
-if you are using one which is it?
-are you including all the modules in the *.pro for quake?
-have you used 4.8 version, did you experienced these problems with that?
P.S. if you do not have any particular necessity I suggest you to stick to version 4.8 for some time (as I am doing without problem) since 5.0 is just been released
Related
I am trying to build a simple SSH client from Wil Allsopp's pen testing book. Working on Mac OS High Sierra with gcc-4.2 with libssh installed using Homebrew. The simplest version of the code is:
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
my_ssh_session = ssh_new();
ssh_free(my_ssh_session);
return 0;
}
However a simple gcc build (gcc -Wall ssh_client.c) produces the following error:
Undefined symbols for architecture x86_64:
"_ssh_free", referenced from:
_main in ssh_client-aa8f09.o
"_ssh_new", referenced from:
_main in ssh_client-aa8f09.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
Can anyone explain these errors and how I can fix them?
Your build line doesn't appear to contain any include and linker flags. I imagine it is picking up the headers but not the library for ssh to link against. Have a look into pkgconfig for an easy way to maintain this.
I'm trying to compile a simple opencv code using Xcode but I'm getting a compilation error.
The opencv version is 3.0.0 and Xcode version is 6.3 (OS X 10.10.3)
In Xcode, Apple LLVM 6.1 Language C++ settings are:
c++ Language Dialect : C++11[-std=c++11]
c++ Standard Library : libc++
the error is:
Undefined symbols for architecture x86_64:
"cv::imread(cv::String const&, int)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I change the c++ standard library to libstdc++, then the error was:
/usr/local/include/opencv2/hal/defs.h:271:14: 'cstdint' file not found
Can someone show me how to get opencv work with Xcode? I've already followed lot of forums and guides but still getting the same error.
I had the same problem, either I got the "Undefined symbols x86_64" with libc++, or "cstdint file not found" with libstdc++.
What finally made it work for me was that I needed to add a lot more libs than I'm used to, it wasn't enough to add just core, imgproc, and highgui for even a simple project.
So I went to Build Settings, searched for Linking, and in Other Linker Flags I added the whole lot:
-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab
I'm using OpenCV 3.0.0 and Xcode 6.4. C++ Standard Library set to libc++ and C++ Language Dialect C++11. Hope this helps!
I have QT creator project, that has CMarkup library, that uses iconv library. On OSX 10.8.4 I'm having widespread issue with iconv library:
Undefined symbols for architecture x86_64:
"_iconv", referenced from:
...
"_iconv_close", referenced from:
...
"_iconv_open", referenced from:
...
This is caused according to Stack's few QA's by not proper build of iconv. So I compiled correct one, but now there is a question that I cannot solve: how can I swap iconv in QT creator project from /usr/lib to /usr/local/lib?
Well, that was obvious, if someone would need this, here is my solution. Add this line to your .pro file:
LIBS += =L/usr/local/lib -liconv
Do not forget to swap iconv.h file from system one, just add it into your project and write:
#include "iconv.h"
instead of
#include <iconv.h>
Hope this will help someone to save some time.
Cheers!
Ok. So here goes. I am currently trying to add and use a dynamic library called OpenCV into a Xcode project of mine. I first installed MacPorts using the .pkg. Then I opened Terminal and ran "sudo port install opencv". MacPorts then installed all sorts of dependencies (FFMPEG/etc) and then installed OpenCV into the "/opt/local/lib" folder for the .dylib files and into "/opt/local/include" folder for the header files. Then I opened Xcode and opened command line utility application project. I added a group to my project and then added all the .dylib files inside of it (I think these are called references to the dynamic libraries, but I am not sure - I am a total beginner - I learned C++, my first programming language, merely a week ago"). After that, I clicked on my project file thing inside of Xcode and went to Build Settings and then changed the "Header Search Paths" under the "Search Paths" tab to the /include folder I mentioned previously. The Library Search Path was already set to the /lib folder since I added the .dylib files already (I think that's what happened - not sure). Anyways, then I copied and pasted the following sample code from the opencv website into my main.cpp file just to test whether or not my library works.
//******************************Sample Code ************************************************
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv ) {
if( argc != 2) {
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1; }
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
if(! image.data ) {
// Read the file
// Check for invalid input
cout << "Could not open or find the image" << std::endl ;
return -1; }
namedWindow( "Display window", CV_WINDOW_NORMAL );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0; }
//********************END OF SAMPLE FILE CODE **********************************************
After I did all that and before I hit run, I think it is important to note that Xcode did not complain that it couldn't find my header files, and also it didn't complain about any syntax errors with the new functions the library should've added. In short, there were no errors highlighted on the main.cpp file. All the errors, however, started showing up after I hit the Run button inside of Xcode. Here are all the errors that it generated:
**************Errors from Xcode after I hit Run*********************************************
Stupid Stack Overflow won't let me post images, so here is the link to the error photo:
*****************END OF BLOCK***************************************************************
So, yeah, I have no clue what I am doing at this point and am totally lost. Did I not follow the correct steps in adding a dynamic library to my project? Oh, and I forgot what it was, but I somehow got Xcode to ignore those semantic issues (I cannot remember how I did this or if that was what I did), but once the semantic issues are ignore, the only error that remains seems to be something related to a "Mach-O Linker Error" which says something on the lines of: "undefined symbols....architecture/etc" and then says that the undefined symbol was one of the library functions that I was calling in my main.cpp file. But that error no longer occurs since I deleted everything and started again. So now the only errors I get are the ones from the picture. So PLEASE HELP!!!! I am absolutely lost and I have been researching for weeks now, but I think the issue with me there is that I have no clue what I am looking for or what question I should be asking. The steps I listed above is only what I have done. Any insight will be much appreciated. THANKS IN ADVANCE!!!!!!
____________EDIT___________________
So I repeated the above steps again, but this time I get this error:
Ld /Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug/OpenCVOptTEST normal x86_64
cd "/Users/Yash/Coding Folder/OpenCVOptTEST"
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug -L/opt/local/lib -F/Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug -filelist /Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Intermediates/OpenCVOptTEST.build/Debug/OpenCVOptTEST.build/Objects-normal/x86_64/OpenCVOptTEST.LinkFileList -mmacosx-version-min=10.8 -stdlib=libc++ -lopencv_calib3d.2.4.6 -lopencv_contrib.2.4.6 -lopencv_core.2.4.6 -lopencv_features2d.2.4.6 -lopencv_flann.2.4.6 -lopencv_gpu.2.4.6 -lopencv_highgui.2.4.6 -lopencv_imgproc.2.4.6 -lopencv_legacy.2.4.6 -lopencv_ml.2.4.6 -lopencv_nonfree.2.4.6 -lopencv_objdetect.2.4.6 -lopencv_photo.2.4.6 -lopencv_stitching.2.4.6 -lopencv_superres.2.4.6 -lopencv_ts.2.4.6 -lopencv_video.2.4.6 -lopencv_videostab.2.4.6 -o /Users/Yash/Library/Developer/Xcode/DerivedData/OpenCVOptTEST-adchdkiefzmijfhahwtzcfqarzkw/Build/Products/Debug/OpenCVOptTEST
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string, std::__1::allocator > const&, int)", referenced from:
_main in main.o
"cv::imread(std::__1::basic_string, std::__1::allocator > const&, int)", referenced from:
_main in main.o
"cv::imshow(std::__1::basic_string, std::__1::allocator > const&, cv::_InputArray const&)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Check out Apple's documentation for working with Dynamic Libraries.
What these errors are telling you is that it can't find the object code (implementations) for these symbols during the Linking phase. From Apple's documentation, it looks like it expects to find the dylibs in /usr/local/lib not /opt/local/lib.
I have been using OpenCV for a while and also the imwrite function, but unfortunately this is not working any more.
I am running with OpenCV 2.4.3 with following sample code:
imwrite("somepath/somefile.png", myMat);
The error:
Undefined symbols for architecture x86_64:
"cv::imwrite(std::string const&, cv::_InputArray const&, std::__debug::vector<int, std::allocator<int> > const&)", referenced from:
MyProject::this_callback(int, void*) in MyProject.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The error looks somewhat familiar but i cannot determine whats wrong.
Yes, I've thought you were using XCode. I had the same problem. :)
If you change the project setup so that:
you use GNU++11 as C++ language dialect
libstdc++ (GNU C++ standard) as C++ standard library
your linking problem will go away.
I use Apple LLVM 4.1.
When I had this problem, I have tried just adding a new target to one of my old projects I knew, worked. Then I've just made that target a one-source-file program.
This must be a "magic" part of XCode as I think there was a time I could not get the same project working after a restart. :S
I did what Barnabas did and also got the issue on cvdef.h. I was getting desperate so and what I did was just changed the header file.
in /usr/local/cvdef.h line 205:
I changed
include <cstdint>
typedef std::uint32_t uint;
to:
include <tr1/cstdint>
typedef std::tr1::uint32_t uint;
based on this post
I think opencv devs should apply some changes to the code for 64bit..
use something like clang version 3.8.0 (trunk 257459), instead of gcc version 4.9.2 (MacPorts gcc49 4.9.2_1+universal) to compile
for reference, cmd: clang++ -std=c++11 `pkg-config --cflags --libs opencv` code.cpp -o code