What is the darwinssl library location on Mac OS X? - c++

I am trying to compile curl and statically link it to another project.
I did manage to compile it for my mac architecture(x86_64) and got "libcurl.a".
Now when I try to build:
#include <curl/curl.h>
int main()
{
CURL *curl = curl_easy_init();
}
with g++ tornado.cc -o tornado (path-to-where-it-is)libcurl.a -std=c++11
I get:
Undefined symbols for architecture x86_64:
"_CFArrayAppendValue", referenced from:
_append_cert_to_array in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayCreate", referenced from:
_darwinssl_connect_common in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayCreateMutable", referenced from:
_darwinssl_connect_step2 in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayGetCount", referenced from:
_darwinssl_connect_common in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayGetValueAtIndex", referenced from:
_darwinssl_connect_common in libcurl.a(libcurl_la-darwinssl.o)
"_CFDataCreate", referenced from:
_append_cert_to_array in libcurl.a(libcurl_la-darwinssl.o)
As I understand it wants to get links for darwinssl, but I do not know where to get those.
The readme for curl (https://github.com/biasedbit/curl-ios-build-scripts/blob/master/README.md) - does mention it depends on libz.dylib and
Security.framework but does not give any clues about what they are, when and how do I need them, and how to include those.
P.S. the regular curl inclusion works fine: g++ tornado.cc -o tornado -lcurl -std=c++11

I found some time to mess around on the mac. Here's the command that worked for me:
gcc main.cpp -I path/to/include path/to/libcurl.a -framework Foundation -lz -framework Security
Basically, you need -framework Foundation, -lz and -framework Security.

Related

PostgreSQL external C function link failed on Mac OSX

I'm trying to build an external PostgreSQL function on OSX 10.11 with both clang and gcc, but link failed with the following errors:
c++ -I/usr/local/Cellar/postgresql/9.5.3/include/server -fpic -c ./main.c
c++ -shared -o ttt.dylib main.o
Undefined symbols for architecture x86_64:
"_deconstruct_array", referenced from:
_psql_nearest in main.o
"_elog_finish", referenced from:
_psql_nearest in main.o
"_elog_start", referenced from:
_psql_nearest in main.o
"_get_typlenbyvalalign", referenced from:
_psql_nearest in main.o
"_pfree", referenced from:
_psql_nearest in main.o
"_pg_detoast_datum", referenced from:
_psql_nearest 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)
It looks like I need to link my library with some of PostgreSQL libraries. What are these libraries?
main.cpp:
extern "C" {
#include <postgres.h>
#include <fmgr.h>
#include <utils/array.h>
#include <utils/lsyscache.h>
#include <catalog/pg_type.h>
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
PG_FUNCTION_INFO_V1(psql_nearest);
Datum psql_nearest(PG_FUNCTION_ARGS) {
if(PG_ARGISNULL(0) || PG_ARGISNULL(1)) {
elog(ERROR, "DOC2VEC: NULL INPUT DATA");
PG_RETURN_NULL();
}
ArrayType *_docVector = PG_GETARG_ARRAYTYPE_P(0);
Oid elTypeVals = ARR_ELEMTYPE(_docVector);
if (elTypeVals != FLOAT4OID) {
elog(ERROR, "DOC2VEC: INVALID INPUT DATA TYPE");
PG_RETURN_NULL();
}
int16 typeLenVals = 0;
bool typeByValVals = false;
char typeAlignVals = char(0);
get_typlenbyvalalign(elTypeVals, &typeLenVals, &typeByValVals, &typeAlignVals);
Datum *inputVals;
bool *nullVals;
int nVals;
deconstruct_array(_docVector, elTypeVals, typeLenVals, typeByValVals, typeAlignVals, &inputVals, &nullVals, &nVals);
pfree(inputVals);
pfree(nullVals);
PG_RETURN_NULL();
}
}
Thanks to PostgreSQL developers, they explained me the difference in Linux and OSX linking of external functions.
Instead of -shared you need -bundle -bundle_loader /path/to/postgres,
and there are some other linker flags that are advisable too.
Also, PostgreSQL expects the file extension for loadable modules to be .so even on OSX.
It's usually better to use PGXS to build extensions, instead of
learning such details for yourself.
Or you can crib from one of the extensions in the contrib/
source tree.
If you need to link, you will need the -L flag to point the linker to the path where the postgres libraries are located (the linker equivalent of the -I compiler flag). and the -l flag to actually link the libraries (one for each library); the library name without the lib prefix and without the extension.
In your case, something along the lines of -L/usr/local/Cellar/postgresql/9.5.3/lib -lpostgres
(There's a variety of library files in that directory; try -lpg to start with.
The reference to _pfree in your error message also suggest to link pgcommon, which contains the implementation of pgree (at least when using nm libpgcommon.a).
)
You may want to read up a bit more on compiling and linking in general; you do the right thing for compiling with the -I flag, but oddly then miss out on the linking step. And learning about make and Makefiles will come in handy.
I also don't understand the extern "C" { part for a .c file, which is clearly a C-only file. extern "C" is usually used in C++ files for compatibility with C.

Running OpenCV 3 in Mac Terminal

For the past week, I have been trying to run some simple OpenCV programs using the terminal. I have tried many tutorials and recommendations from various forums with little success. The problem arises when trying to link the OpenCV header files to my OpenCV main program. For a simple c++ program I would simply execute g++ main.cpp header.hpp to generate the program executeable. How do I go about linking the necessary OpenCV header files such as <opencv2/highgui/highgui.hpp> & <opencv2/core/core.hpp>?
For example, when attempted to execute the sample program from http://docs.opencv.org/2.4/doc/tutorials/introduction/display_image/display_image.html the following occurs:
Desktop Robert$ g++ loadIMG.cpp
Undefined symbols for architecture x86_64:
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in loadIMG-54c517.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in loadIMG-54c517.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
cv::Mat::operator=(cv::Mat const&) in loadIMG-54c517.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in loadIMG-54c517.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in loadIMG-54c517.o
"cv::imread(cv::String const&, int)", referenced from:
_main in loadIMG-54c517.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in loadIMG-54c517.o
"cv::waitKey(int)", referenced from:
_main in loadIMG-54c517.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in loadIMG-54c517.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please note: OpenCV has already been built using the following tutorial: http://blogs.wcode.org/2014/10/howto-install-build-and-use-opencv-macosx-10-10/
Any help or direction would be appreciated. Thank you.
You haven't specified:
the include path (header search path) using -I"/path/to/your/include"
the path to the libraries using -L"/path/to/libraries"
which libraries to link against, in this case core and highgui: -lopencv_core -lopencv_highgui
I have opencv headers in /opt/local/include and libraries in /opt/local/lib,
so to compile a basic program like this:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
Mat src = Mat(Size(320,240),CV_64F);;
namedWindow("test");
cout << "press any key to close" << endl;
while(true){
randn(src,0,1.0);
imshow("test",src);
if(waitKey() > 0) break;
}
}
I compiled like so:
g++ main.cpp -I"/opt/local/include/" -L"/opt/local/lib/" -lopencv_core -lopencv_highgui -o main
Then ran ./main:
Bare in mind you might have opencv installed in the /usr/local folder not /opt/local depending how you compiled/installed OpenCV.
Also, you might have pkg-config installed which can come in handy when you need to link against more libraries.
For example, you can run:
pkg-config --libs --cflags opencv
which in my case outputs:
-I/opt/local/include/opencv -I/opt/local/include -L/opt/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
but in your case, it should output your particular OpenCV paths.
This would simplify compiling to this:
g++ main.cpp `pkg-config --libs --cflags opencv` -o main
The guide you linked to uses cmake which generates Makefiles for you.
That's another nice options. Also, based on the same guide, you should have XCode installed which you can use to create a Command Line Tool and point the Header Search Paths and Library Search Paths.
I create a similar file that maybe can help you.
First I use:
sudo brew install opencv
Then I install the opencv.3.0 according to the hint given by the terminal. Then in the .cpp file which needs the API from opencv, I use:
#include "opencv2/opencv.hpp"
As my only include file about opencv. Actually, at that project I use highgui, core, and imgprog. But no worries here, I will show you how to solve them in linking part.
After you finish your project, you are going to compile your project on the terminal.
Because I also used the JNI interface, so I still need to link the jni.h.
Here we go:
g++ xxxx.cpp xxx.cpp -lstdc++ -fPIC -shared (to create a shared object)
-I/absolute path/ (we can use -I to be followed with the absolute path of the library you need to use )
-I/Users/yuanzhan/Downloads/OpenCV-2.0.0/src/
-I /Users/yuanzhan/Downloads/OpenCV-2.0.0/include/opencv/ -I/usr/local/Cellar/opencv3/3.1.0_3/lib -lopencv_core (open the library for use if you use the API fro here)-lopencv_highgui -lopencv_imgproc -L.(i put the cv2. on local otherwise you can add the absolute path here) -lcv2(use the package) -v -o libopenCvSDK.so(generate my .so package).

boost::filesystem Undefined symbols for architecture x86_64

I am very new with using GNU. I am trying to start using the boost filesystem library, and I keep getting these errors. I am trying to get the current working directory, by using boost::filesystem.
My code:
boost::filesystem::path full_path( boost::filesystem::detail::current_path() );
cout << "Current path is : " << full_path << endl;
My command:
g++ -I boost_1_58_0 main.cpp -o example
Result:
Undefined symbols for architecture x86_64:
"boost::filesystem::detail::current_path(boost::system::error_code*)", referenced from:
_main in main-1c56eb.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main-1c56eb.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in main-1c56eb.o
___cxx_global_var_init1 in main-1c56eb.o
ld: symbol(s) not found for architecture x86_64
Can someone please explain what the error is asking for? What did I do wrong?
boost.filesystem is not a header-only library. You have to link to the library using -L and -l flags. (And make sure the library is already properly built). You need to link to both boost_system and boost_filesystem libraries.
The command line could look like:
g++ -Iboost_1_58_0 -Lboost_1_58_0/lib/ -lboost-filesystem -lboost_system main.cpp -o example
(replace the -L argument with the path where the libboost-filesystem.so file resides)
Then, before you are able run the executable, you have to let the loader know where to look for the libraries. You shell be able do that using the following command:
export DYLD_LIBRARY_PATH=/path/to/boost/bib:$DYLD_LIBRARY_PATH
To make it automatic, I would recommend using a build system like cmake instead of just a command line.

apple mach o linker error creating basic AI CC Plugin

there are quite a no. of question on this point. But none of them can guide a solution to my issue. I am trying to create a plugin for Adobe Illustrator CC in XCode Version 6.3.2 (6D2105). Following their official guidelines to create a basic "HelloWorld" plugin giving this linker error.
Error:
Ld /Users/Barun/Adobe\ Illustrator\ CC\ 2015\ SDK/samplecode/output/mac/debug/HelloWorld.bundle/Contents/MacOS/HelloWorld normal x86_64
cd "/Users/Barun/Adobe Illustrator CC 2015 SDK/samplecode/HelloWorld"
export MACOSX_DEPLOYMENT_TARGET=10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/Barun/Adobe\ Illustrator\ CC\ 2015\ SDK/samplecode/output/mac/debug -F/Users/Barun/Adobe\ Illustrator\ CC\ 2015\ SDK/samplecode/output/mac/debug -filelist /Users/Barun/Library/Developer/Xcode/DerivedData/HelloWorld-fzhjlvdzxxobzagznysauclanlgg/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld.LinkFileList -mmacosx-version-min=10.9 -dead_strip -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/Barun/Library/Developer/Xcode/DerivedData/HelloWorld-fzhjlvdzxxobzagznysauclanlgg/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld_dependency_info.dat -o /Users/Barun/Adobe\ Illustrator\ CC\ 2015\ SDK/samplecode/output/mac/debug/HelloWorld.bundle/Contents/MacOS/HelloWorld
Undefined symbols for architecture x86_64:
"_CFStringCreateWithCharacters", referenced from:
ai::UnicodeString::as_CFString(__CFAllocator const*) const in IAIUnicodeString.o
"_CFStringGetCharactersPtr", referenced from:
ai::UnicodeString::UnicodeString(__CFString const* const&) in IAIUnicodeString.o
"_CFStringGetLength", referenced from:
ai::UnicodeString::UnicodeString(__CFString const* const&) in IAIUnicodeString.o
"_CFStringGetCharacters", referenced from:
ai::UnicodeString::UnicodeString(__CFString const* const&) in IAIUnicodeString.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Looks like the linking error coming from IAIUnicodeString.cpp file, which is a support file provided by the sdk. So I am not having idea to what need to be change there.
I was successful to build FreeGrid and DrawArt project provided with the SDK as sample. I have also checked all the build settings with FreeGrid to my HelloWorld project, no mismatch from that side too.
The project set up can be found in Github.
From Adobe Forum https://forums.adobe.com/message/7723859#7723859:
Add to project settings:
BuildPhases>Link Binary With Libraries: CoreFoundation.framework

Apple Mach-O Linker (Id) Error using gSOAP

I´m really stuck with this issue... and i hope you can help me out here.
I'm developing an iPad app for a company, that requires to use secured SOAP web services... not the perfect combination! i know, the thing is that taking a look around google, i found that the "best" thing to do was making a WS client using gSOAP and that´s what i did! now i have the client for one of those WS in C++.
When i try to call one of the methods of the WS, and build the app... this is what happens:
Ld /Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator/App.app/App normal i386
cd /Users/me/iOS/App
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch i386 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk
-L/Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator
-L/Users/me/iOS/App -F/Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator
-F/Applications/Xcode.app/Contents/Developer/Library/Frameworks
-filelist /Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Intermediates/App.build/Debug-iphonesimulator/App.build/Objects-normal/i386/App.LinkFileList
-mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100
-framework SenTestingKit -framework Foundation -framework UIKit -framework QuartzCore -framework CoreGraphics -ldataSOAPlibDev
-o /Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator/App.app/App
ld: warning: ignoring file /Users/me/iOS/App/libdataSOAPlibDev.a,
file was built for archive which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
'soap::soap()', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'_soap_init_LIBRARY_VERSION_REQUIRED_20808', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'soap_call_ns1__obtenerPais(soap*, char const*, char const*, ns2__paisFile*,
ns1__obtenerPaisResponse&)', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'soap::~soap()', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'ns2__paisFile::soap_default(soap*)', referenced from:
ns2__paisFile::ns2__paisFile() in ViewContratosController.o
'vtable for ns2__paisFile', referenced from:
ns2__paisFile::ns2__paisFile() in ViewContratosController.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The NOTE may tell the problem... but i don´t know how to solve it... any ideas?
Thanks!
The problem is probably that you took a library for iPAd (ARM architecture) and tried to build to the simulator (i386 architecture). Try building to the actual device instead.
The hint for me was:
ld: warning: ignoring file /Users/me/iOS/App/libdataSOAPlibDev.a, file
was built for archive which is not the architecture being linked
(i386)
OK! i solved it including (not importing) the headers and the nsmap generated by gSOAP in the .mm file where i´m trying to consume the WS...
#include "soapH.h"
#include "soapStub.h"
#include "soapdataServiceSoapBindingProxy.h"
#include "dataServiceSoapBinding.nsmap"
If you are going to make a static library out of a WS Client created by gSOAP, be REALLY careful with the "Build Phases" of the library Project... add carefully the headers and the compile sources!
After that... import to your iOS proyect the "lib.a" with the headers and the XMLs under the same folder! and call the WS doing something like this:
dataServiceSoapBinding service;
ns2__countryFile country;
struct ns1__getCountryResponse response;
country.idCountry = 11;
if(service.ns1__getCountry(&country, response) == SOAP_OK) {
NSLog(#"ok");
} else {
NSLog(#"ERROR");
}
I hope this may help anybody... because i had such a hard time figuring this out... and didn´t find much info about it!
:)