openSSL mac undefined symbol - c

I'm developing a TLSclient for MAC, and I'm having a little building my project on MACOSX (working very well on linux) and most particulary in using openssl libs.
Here's my console error I hope you could help me deal with:
gcc -lpthread -o *.o /opt//local/var/macports/software/openssl97/0.9.7m_0/opt/local/lib/openssl97/lib/libssl.a /opt//local/var/macports/software/openssl97/0.9.7m_0/opt/local/lib/openssl97/lib/libcrypto.a -ldl
Undefined symbols:
"_SSL_CTX_set_info_callback", referenced from:
_MTLSServer_Setup in MTLSServer.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [mtls_server] Error 1
Thanks for your help

In OpenSSL 0.9.7 SSL_CTX_set_info_callback is a macro, and your code is trying to link to a function. This probably means you don't have the correct path to the headers.
I'm a little puzzled for other things in your command line:
Why are you statically linking with an old version of OpenSSL 0.9.7. Recent versions of Mac OS X have 0.9.8 included.
The -o *.o seems to be an error it should be -o something *.o
The -lpthread argument should be after libcrypto.

Related

Is it posible to compile Flex/Lex on a M1 Mac

In my compilers class we are writting Flex/Lex code. When I compiled the .l file and tried to compile the resultant lex.yy.c file with gcc, I got the following error:
Undefined symbols for architecture arm64:
"_yywrap", referenced from:
_yylex in lex-fb85c9.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does is posible to compile it in a Apple Silicon (M1) Mac, at least in a Linux VM?
I created a test file and compiled:
% flex lex.l
% cc -o lex lex.yy.c -lc -ll
% grep 'yylex();' lex.yy.c
yylex();
The -ll on the cc command links against the libl library. Current M1 based macOS does not provide a libfl library you may see referenced.

DSO missing from command line although it is available

I am working with c++ code for a physics simulation, which uses a lot of external libraries (like GSL and cern`s ROOT). Trying to recompile project I encountered problems with linking. When running compilation of final file via:
g++ -fno-inline -O2 -fpic -o main.out ${ROOTINCS} main.o ext.o ${ROOTLIBS} $(objects2)
with :
objects2= many .o files made by us
ROOTLIBS=-L/usr/local/lib/root -lTree -lRIO -lNet -lHist -lMathCore -lCore -lGraf -lGraf3d -lGpad -lMatrix -lThread -lCint -lPhysics -lPostscript -lRint -lSpectrum -lg
ROOTINCS=-pthread -m64
I get annoying error:
/usr/bin/ld: /usr/local/lib/root/libHist.so: undefined reference to symbol 'gRandom'
/usr/local/lib/root/libMathCore.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
The problem is nm -C run on libMathCore states 'gRandom' is declared there. Also -lMathCore is present in my command line.
When I run ld to check if it understands the flag:
ld -L/usr/local/lib/root -lMathCore --verbose 2>/dev/null
it does not complain and tries to link properly.
According to https://stackoverflow.com/a/24675715/3602168 order of libraries is correct in my linking (libHist uses libMathCOre and therefore is stated first).
Compilation runs under g++ 4.8.2 on ubuntu 14.04, 64 bit
Converting comment to answer:
Have you tried moving $(objects2) before ${ROOTLIBS}? I think the issue may be that you have libraries specified before the object files that use them.

Underbars in symbol names when linking against an external library

I'm trying to compile a C library and then some external C code liked against it and I'm having issues with my external code finding the symbols within the library. I don't understand the big flick and am hoping someone can help. Here are the details:
1) I'm working on a Mac. I've compiled the library as a static .a library in xcode.
2) I'm attempting to compile external code calling functions from the library. I've included the header file and I'm specifying it's location and the library in the gcc call. The compilation seems to complete ok, but the linking fails stating that symbols cannot be found.
3) The missing symbols are listed as _FunctionName where FunctionName is the name of the function I called.
It is not clear to me why the compiler/linker has added underbars to my function names. But my naive guess is that is why the symbols can not be found in the library.
The external code compilation is being done through MATLAB's mex() function which is making the gcc calls below in the background.
I'd be thankful for any thoughts anyone might have.
gcc-4.2 -c -Igsf_0303/ -I/Applications/MATLAB_R2011b.app/extern/include \
-DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -arch x86_64 -isysroot \
/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -fexceptions \
-DMX_COMPAT_32 -O2 -DNDEBUG "gsf_tester.c"
gcc-4.2 -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl, \
-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,\
-exported_symbols_list,/Applications/MATLAB_R2011b.app/extern/lib/maci64/mexFunction.map \
-o "gsf_tester.mexmaci64" gsf_tester.o gsf_0303/libgsf.a \
-L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
Undefined symbols:
"_gsfOpen", referenced from:
_mexFunction in gsf_tester.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
mex: link of ' "gsf_tester.mexmaci64"' failed.
Here's a guess. Firstly, Joachim's comment is correct. C function names will always be prepended with an underscore. So that's not the issue.
So either gfsOpen() is missing from the library or it's not visible or it can't be seen when gfs_tester.o is linked.
So check that gfsOpen is in the library. This should do it
otool -t -v sgsf_0303/libgsf.a | grep gsfOpen
The above disassembles the file and then greps the symbol you are interested in from it. There's probably a better way, but I haven't bothered to research it.
Check it's not declared static.
Make sure the architecture of the library matches (otool -fv)

Erlang NIF Test -- OS X Lion

I'm trying to compile the NIF Test from Erlang (http://www.erlang.org/doc/man/erl_nif.html) on Mac OS X Lion. I can't get it to compile. Am I missing a compiler flag? Here's the error I get:
Computer:~ me $ gcc -fPIC -shared -o niftest.so niftest.c -I /usr/local/Cellar/erlang/R14B02/lib/erlang/usr/include/
Undefined symbols for architecture x86_64:
"_enif_make_string", referenced from:
_hello in ccXfh0oG.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I've also tried this with -m32 but it says there's no i386 architecture either.
Thanks!
for 64-bit Erlang, the following works for me:
gcc -undefined dynamic_lookup -dynamiclib niftest.c -o niftest.so \
-I /usr/local/Cellar/erlang/R14B02/lib/erlang/usr/include
It seems like your problem is not architecture but undefined symbol _enif_make_string, which means that you have to link with your enif library, whatever it is, using -l option. Also, it's been a long time since I built a shared library for OS X, but I think that the right flag to use is -dynamiclib and not -shared, and you don't have to have a space after -I.
Try using these flags when compiling your nif instead of -shared
-bundle -flat_namespace -undefined suppress

Compiling and Linking a C-Program for a 32-bit Architecture

So I'm working through an assignment for Stanford's CS107 course and I can't get past compiling the unfinished program (project files and the original makefile can be found on the course page, I'm working on assignment 4 RSS.)
After much research, I think the problem is I'm using gcc on a 64-bit architecture (Mac OS 10.6) and the pre-compiled library code under assn-4-rss-news-search-lib/linux is for a 32-bit architecture. I tried setting gcc to use i386 and -m36, but nothings working and I'm kind of just guessing.
So here's the output I get when I run make:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lnsl -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: library not found for -lnsl
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
Here's the output I get when I remove -lnsl where architecture differences are mentioned:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: warning: in /Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux/librssnews.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols:
"_URLConnectionDispose", referenced from:
_ProcessFeed in rss-news-search.o
_ParseArticle in rss-news-search.o
... several more undefined symbols mentioned ...
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
So I'm asking for any ideas on what I could do to resolve this. I've been at it for hours tweaking settings and Google'ing around to no avail.
In case someone like me will be looking for answer after all this time passed...
Problem is easy solved by installing wubi version of 32bit Ubuntu. It works fine on 64bit system. You only need to edit makefile so it knows where to look for the libraries provided.
I'm pretty sure that using a precompiled library for linux on macos, whatever the bitness, won't work (well, it is probably possible to cross-compile on MacOS for Linux and perhaps possible to run Linux executable in a compatibility box on MacOS, but that's quite different than what you are trying to do).
libnsl is a standard library on Linux (it provides some networking related functions)

Resources