I'm trying to use CBLAS ATLAS. I'm a beginner. I have the following C code.
// tmp.cpp file
#include<stdio.h>
#include<stdlib.h>
#include<cblas.h>
int main(void){
float x[2] = {6,2};
float *y = (float *)malloc(2*sizeof(float));
const int n = 2;
const int incx = 1;
const int incy = 1;
float a = 5.4;
y[0] = 4.2; y[1] = 4.5;
cblas_saxpy(n,a,x,incx,y,incy);
free(y);
}
I installed the ATLAS library following the video http://youtu.be/DvLSr6zN0pU?t=6m5s and the next video "part3". However, I have no FORTRAN compiler, so I configure with
$../ATLAS/confiugre --nof77
The installation process took place as described in the video.
iMac:Desktop sotero$ ls /usr/local/atlas/include
atlas cblas.h clapack.h
iMac:Desktop sotero$ ls /usr/local/atlas/lib/
libatlas.a libcblas.a liblapack.a libptcblas.a
I tried compiling with this result
iMac:Desktop sotero$ c++ tmp.cpp
tmp.cpp:3:18: error: cblas.h: No such file or directory
tmp.cpp: In function ‘int main()’:
tmp.cpp:14: error: ‘cblas_saxpy’ was not declared in this scope
I read how to make the link to the website http://math-atlas.sourceforge.net/errata.html#LINK and I have the following to compile
iMac:Desktop sotero$ c++ tmp.cpp -L/usr/local/atlas/lib/ -lcblas -latlas -I/usr/local/atlas/include/
Undefined symbols:
"cblas_saxpy(int, float, float const*, int, float*, int)", referenced from:
_main in ccPop12J.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I do not know how I should compile. I just need to level one BLAS. I've been looking to compile if you do link to the ATLAS library, but I'm lost.
How I can fix it?
Related
Xcode 6 GM and its LLVM 6 give this linking error:
Undefined symbols for architecture i386:
"_fopen$UNIX2003", referenced from:
_BIO_new_file in libcrypto.a(bss_file.o)
_file_ctrl in libcrypto.a(bss_file.o)
_open_console in libcrypto.a(ui_openssl.o)
"_fputs$UNIX2003", referenced from:
_write_string in libcrypto.a(ui_openssl.o)
_read_string in libcrypto.a(ui_openssl.o)
"_fwrite$UNIX2003", referenced from:
_send_fp_chars in libcrypto.a(a_strex.o)
_write_fp in libcrypto.a(b_dump.o)
_file_write in libcrypto.a(bss_file.o)
_file_puts in libcrypto.a(bss_file.o)
"_strerror$UNIX2003", referenced from:
_ERR_load_ERR_strings in libcrypto.a(err.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Now, this answer suggests adding an ad-hoc .c file which, for the case above, would be:
#include <stdio.h>
#include <string.h>
FILE *fopen$UNIX2003( const char *filename, const char *mode )
{
return fopen(filename, mode);
}
size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )
{
return fwrite(a, b, c, d);
}
void fputs$UNIX2003(const char *restrict c, FILE *restrict f)
{
fputs(c, f);
}
char *strerror$UNIX2003(int errnum)
{
return strerror(errnum);
}
It 'works', but is this the best (or even advisable) approach?
As you guessed, no, that would not be an advisable approach to fix your LLVM linker woes in Xcode 6. Instead, assuming you're developing for iOS, what you need to do is rebuild OpenSSL for the new iOS 8 SDK. Here's a good project that will help you do that.
in case this can save anyone some time, there's I've found to fix this specific linkers issues (adding this to any any cpp file):
extern "C"{
size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )
{
return fwrite(a, b, c, d);
}
char* strerror$UNIX2003( int errnum )
{
return strerror(errnum);
}
time_t mktime$UNIX2003(struct tm * a)
{
return mktime(a);
}
double strtod$UNIX2003(const char * a, char ** b) {
return strtod(a, b);
}
}
My question is in regards to using OpenSSL on Mac via GCC.
#include <stdio.h>
#include <openssl/rand.h>
int main()
{
unsigned char key[128];
Rand_bytes(key,128);
return 0;
}
I have the following code, that I am trying to compile with GCC. Here is what I enter into the command line
gcc -o ossl ossl.c -lcrypto -lssl
However I get the following error.
Undefined symbols for architecture x86_64:
"_Rand_bytes", referenced from:
_main in cc2hf0Ij.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I am not experienced when it comes to using openssl. Why am I receiving Undefined symbols for architecture x86_64?
int main()
{
unsigned char key[128];
Rand_bytes(key,128);
return 0;
}
Try RAND_bytes:
int main()
{
unsigned char key[128];
int rc = RAND_bytes(key,sizeof(key));
if(rc != 1)
/* Handle failure */
...
OPENSSL_cleanse(key,sizeof(key));
return 0;
}
The OpenSSL docs are at RAND_bytes(3).
Goal: I want to use thread STL of C++11 in Matlab mex file (R2013a) using Xcode 4.6
I modified ~/.matlab/R2013a/mexopts.sh
CC='clang++' # was llvm-gcc-4.2
CXX='clang++' # was llvm-g++-4.2
MACOSX_DEPLOYMENT_TARGET='10.8' # was 10.5. C++11 is supported >=10.7
CXXFLAGS="$CXXFLAGS -std=gnu++11 -stdlib=libc++" # additional flags
Normal mex files without C++11 features are compiled well. Further, STL is well detected by the compiler except linking failure.
>> mex mextest.cpp
Undefined symbols for architecture x86_64:
"std::__1::__thread_struct::__thread_struct()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<void (*)()> >(void*) in mextest.o
"std::__1::__thread_struct::~__thread_struct()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<void (*)()> >(void*) in mextest.o
"std::__1::__thread_local_data()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<void (*)()> >(void*) in mextest.o
"std::__1::__throw_system_error(int, char const*)", referenced from:
_mexFunction in mextest.o
"std::__1::thread::join()", referenced from:
_mexFunction in mextest.o
"std::__1::thread::~thread()", referenced from:
_mexFunction in mextest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "mextest.mexmaci64"' failed.
Error using mex (line 206)
Unable to complete successfully.
The actual source code is shown below. The details are not important because it compiles well in Matlab R2013 WINDOWS version with Visual Studio 2012 Express. An equivalent cpp was also well compiled with "clang++ -std=gnu++11 -stdlib=libc++ clangtest.cpp". So, at least, there is no logical error in the codes (I'm not saying it is safe codes. It is just a test.)
#include "mex.h"
#include <thread>
#include <stdio.h>
int count_thread1 = 0;
int count_thread2 = 0;
void hello()
{
count_thread2 = 0;
for(int i=0; i<=10000; i++){
for (int j=1;j<=20000;j++){
count_thread2 = i-j-1;
}
count_thread2++;
printf("2: %d , %d\n", count_thread1, count_thread2); // Not sure if printf is thread-safe in Matlab. But it works in this particular example
}
}
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
count_thread1 = 0;
std::thread t(hello);
for (int i=1;i<=10000;i++)
{
for (int j=1;j<=20000;j++){
count_thread1 = -i+j-1;
}
count_thread1++;
mexPrintf("1: %d , %d\n", count_thread1, count_thread2);
}
mexPrintf("\n");
t.join();
mexPrintf("Done\n");
}
It seems like I have to replace some include directories and/or library directories. What kind of options should be modify?
Thank you.
The error is due to compiling against -stdlib=libc++ but linking against -lstdc++. You can fix it in one of two ways:
Fix it in mexopts.sh. The most drastic and effective solution. Located in ~/.matlab/${MATLAB_VERSION}/mexopts.sh, this determines all compiler options. Simply find/replace all stdc++ to c++.
Patchwork solution: Simply add -lc++ to the tail end of CXXLIBS. I'm not sure what the effect of linking against multiple versions of the standard libraries is, but it seems to work. In your mex invocation, add the argument CXXLIBS="\$CXXLIBS -lc++".
As a secondary issue, I believe you're completely overwriting the value of CXXFLAGS; you must escape the $ symbol as I did above with the libraries.
I have installed opencv with macports following the directions here: Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode
I have also search and tried every other variation of this on stackexchange and google, but this seems to get me closest.
It seems to work for some things, but not for sample code that ships with 2.4.2. Note that I have added ALL opencv 2.4.2 dylibs Link Binary with Libraries.
For example, the following will compile and run:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
int main ( int argc, char **argv )
{
cvNamedWindow( "My Window", 1 );
IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
CvFont font;
double hScale = 1.0;
double vScale = 1.0;
int lineWidth = 1;
cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
hScale, vScale, 0, lineWidth );
cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
cvScalar( 255, 255, 0 ) );
cvShowImage( "My Window", img );
cvWaitKey();
return 0;
}
However, when I try to build any of the samples, such as the display_image.cpp, example, as follows, I get link errors.
-DOES NOT WORK-
#include <stdio.h>
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/flann/miniflann.hpp"
using namespace cv; // all the new API is put into "cv" namespace. Export its content
using namespace std;
using namespace cv::flann;
static void help()
{
cout <<
"\nThis program shows how to use cv::Mat and IplImages converting back and forth.\n"
"It shows reading of images, converting to planes and merging back, color conversion\n"
"and also iterating through pixels.\n"
"Call:\n"
"./image [image-name Default: lena.jpg]\n" << endl;
}
int main(int argc, char *argv[])
{
help();
const char* imagename = argc > 1 ? argv[1] : "lena.jpg";
Mat img = imread(imagename); // the newer cvLoadImage alternative, MATLAB-style function
if(img.empty())
{
fprintf(stderr, "Can not load image %s\n", imagename);
return -1;
}
if( !img.data ) // check if the image has been loaded properly
return -1;
Mat img_yuv;
cvtColor(img, img_yuv, CV_BGR2YCrCb); // convert image to YUV color space. The output image will be created automatically
vector<Mat> planes; // Vector is template vector class, similar to STL's vector. It can store matrices too.
split(img_yuv, planes); // split the image into separate color planes
imshow("image with grain", img);
waitKey();
return 0;
}
I get the following errors:
Undefined symbols for architecture x86_64:
"cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)", referenced from:
_main in main1.o
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in main1.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in main1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea how to resolve this?
I had the same problem. A build setting default seems to be different in Xcode 4.5.
Under "Build Settings"--> Apple LLVM compiler 4.1 - Language >
C++ Standard Library:=
Change from libc++ (LLVM ...) to libstdc++ (GNU C++ ...).
It's very likely that OpenCV has not been compiled with C++11 settings, while the program is.
Set the build of your tool without C++11 switches (i.e. -std=c++11 -stdlib=libc++).
Try to manually add the directory where port puts all the dylibs (/opt/local/lib if I'm not getting wrong) in Build Settings->Library search path. This should fix the linking problem.
Error: " Undefined symbols for architecture x86_64:
"f(int, int, int const (*) [8], int const (*) [8], int*, 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)
I tried running the exact same code on Visual Studio 2010, and it worked! Any idea why it doesn't work here? My Mac is 64bit. Thanks!
Here's the code on the files that's giving the error:
#include <iostream>
using namespace std;
int p,q;
int f( int, int,const int [][8],const int [][8], int [],int []);
This happens if you haven't provided an implementation of your f(..) function.
In your main.cpp file, simply implement the function, like:
int f( int, int,const int [][8],const int [][8], int [],int [])
{
// Do stuff...
}