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!
Related
I am trying to find a portable way of generating modules (dlopen, dlsym, dlerror, dlclose) with CMake.
The whole source code of my attempt is located here.
Here is the CMake script:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(dlopen_example CXX)
ADD_EXECUTABLE(main main.cpp print_ref.cpp)
TARGET_LINK_LIBRARIES(main dl)
ADD_LIBRARY(module MODULE module.cpp)
IF(APPLE)
SET_TARGET_PROPERTIES(module PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
ENDIF(APPLE)
As you may remark, I have to add
-undefined dynamic_lookup
to the set of link flags on Mac OSX (clang compiler). Indeed, while there is no problem on Linux Ubuntu, I get an error message on Mac OSX if I do not add this flag and let CMake handle flags with the line
ADD_LIBRARY(module MODULE module.cpp)
The error message I get is the following:
Undefined symbols for architecture x86_64:
"print_ref()", referenced from:
_module in module.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am surprised that the MODULE option of ADD_LIBRARY does not handle such a flag.Is there a portable solution to this problem with CMake?
I recently started working on a podSpec file that integrates levelDB into my projects.
(https://github.com/iljaiwas/Podspecs/blob/master/LevelDBPodSpec/0.0.1/leveldb.podspec)
However, when I reference any C++ symbol from a .mm file in the main target, I get a linker error like this:
Undefined symbols for architecture x86_64:
"leveldb::DB::Open(leveldb::Options const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, leveldb::DB**)", referenced from:
-[IHLevelDBContext initWithPath:] in IHLevelDBContext.o
This is what the compiler invocation looks like
/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/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug -F/Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug -filelist /Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Intermediates/LevelDBTest2.build/Debug/LevelDBTest2.build/Objects-normal/x86_64/LevelDBTest2.LinkFileList -mmacosx-version-min=10.7 -ObjC -fobjc-arc -fobjc-link-runtime -stdlib=libc++ -framework Cocoa -lPods -o /Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug/LevelDBTest2.app/Contents/MacOS/LevelDBTest2
From my understanding, the missing ::Open call is included in libPods.a
nm libPods.a | grep "Open"
U __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
000000000005e5b1 s L___func__._ZN7leveldb6DBImpl24OpenCompactionOutputFileEPNS0_15CompactionStateE
00000000000099d0 T __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
0000000000060ba0 S __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_.eh
It seems I can get around the linker errors by changing the "Compiler" setting for the main app from Apple LLVM 4.2 to LLVM GCC 4.2, but this compiler chokes on Objective-C 2.0 features, like this:
expected a property attribute before 'strong'
Thanks for any pointers on what I might be doing wrong,
Ilja
You can also set the C++ config settings in the podspec file:
s.library = 'c++'
s.xcconfig = {
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11',
'CLANG_CXX_LIBRARY' => 'libc++'
}
Those settings selects to compile for C++ 2011 and adds the libc++ standard library.
The problem went away after I set the "C++ Standard Library" setting in both the application target and CocoaPods target to "compiler default". Seems they were set to incompatible values by default, which caused linker confusion afterwards.
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
Hi, I am using Xcode 4 and trying to set up FLTK 1.3.0 to run Bjarne
Stroustrup's Chapter 12 FLTK Demo at the end of the chapter. I keep
getting the following error when compiling, and have no idea where to go.
I have an idea it might have to do with the linker flags, but I don't know
what flag to add and where...
Here's the error:
Undefined symbols for architecture x86_64:
"Fl_JPEG_Image::Fl_JPEG_Image(char const*)", referenced from:
Graph_lib::Image::Image(Point, String,
Graph_lib::Suffix::Encoding) in Graph.o
"Fl_GIF_Image::Fl_GIF_Image(char const*)", referenced from:
Graph_lib::Image::Image(Point, String,
Graph_lib::Suffix::Encoding) in Graph.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Are you passing the linker flags present with --use-images? try:
> fltk-config --use-images --ldflags
and check the results to make sure you're getting either the system image libs, or the ones optionally built with fltk.
I also found this to be quite useful:
fltk-config --compile test.cpp
It worked perfectly for me.
For more examples of using fltk-config check out http://www.fltk.org/doc-1.1/basics.html
I am using Xcode 3.0 to compile a test C program using CFITSIO library.
Following advice I have encountered from previous posts, I have built CFITSIO as a universal library, and added the fitsio.h and libcfitsio.a files to my project. I have verified I am using the correct build (x86_64). I have verified the libcfitsio.a file is under the Target > Link Binary with Libraries tab. I continue to receive the following error.
A previously created project using cfitsio works - I wasn't the one to link the library.
Also, I can link cfitsio successfully from terminal.
Any suggestions?
Building target “test1” of project “test1” with configuration “Release”
Checking Dependencies
ld /Users/jacqueline/test1/build/test1.build/Release/test1.build/Objects-normal/ppc/test1 normal ppc
cd /Users/jacqueline/test1
/Developer/usr/bin/gcc-4.0 -o /Users/jacqueline/test1/build/test1.build/Release/test1.build/Objects-normal/ppc/test1 -L/Users/jacqueline/test1/build/Release -L/Users/jacqueline/test1 -L/Users/jacqueline/test1/cfitsio/build/i386 -L/Users/jacqueline/test1/cfitsio/build/ppc -L/Users/jacqueline/test1/cfitsio/build/x86_64 -L/Users/jacqueline/test1/cfitsio/lib -L/Users/jacqueline/test1/cfitsio -F/Users/jacqueline/test1/build/Release -filelist /Users/jacqueline/test1/build/test1.build/Release/test1.build/Objects-normal/ppc/test1.LinkFileList -lcfitsio -arch ppc -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
ld: warning in /Users/jacqueline/test1/libcfitsio.a, file is not of required architecture
Undefined symbols:
"_ffopentest", referenced from:
_main in main.o
"_ffclos", referenced from:
_main in main.o
"_ffgrec", referenced from:
_main in main.o
"_ffghsp", referenced from:
_main in main.o
"_ffrprt", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
It seems as though the library is not fully universal. Try building your project for just one of the architectures at a time (i.e., just ppc, ppc64, i386, and x86-64 separately). When (if) one of them fails, you know which architecture your library is missing so you can recompile it with that. (Or, alternatively, if you don't intend to deploy on that architecture, you can just not compile for it. For instance, there's no real point in building PPC 64 unless you really will benefit from it, as the only machines that will run it are G5s, and they'll run plain old PPC 32-bit code just fine.)
Once I edited Xcode
'Project' > 'Edit Project Settings' > 'Architecture'
to not include PPC, which seemed to be there by default, the build succeeded. I am running OSX 10.5.8 on Intel Core 2 Duo.
Previously I had been using various builds of the cfitsio library itself, and not changing the default architecture on my Xcode project.