I have source file
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>
#define BUFSIZE 1024
int main() {
char line[BUFSIZE];
lua_State *L = lua_open();
while (fgets(line, sizeof(line), stdin) != 0) {
lua_dostring(L, line);
}
lua_close(L);
exit(0);
}
Then I run gcc luac.c, got an error.
Undefined symbols for architecture x86_64:
"_lua_close", referenced from:
_main in luac-9bbdf6.o
"_lua_dostring", referenced from:
_main in luac-9bbdf6.o
"_lua_open", referenced from:
_main in luac-9bbdf6.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 seems like that I have no lua.h in my /usr/local/include folder. But it have.
ls -al /usr/local/include/lua.h
-rw-r--r--# 1 root admin 11K Apr 3 16:23 /usr/local/include/lua.h
And I have
ls -al /usr/local/lib/liblua.a
-rw-r--r-- 1 root admin 150448 Apr 3 16:23 /usr/local/lib/liblua.a
The gcc search path
gcc -Xlinker -v
(#)PROGRAM:ld PROJECT:ld64-305
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
...
Why gcc says error, can you tell me.
Updated:
The problem is gcc default doesn't add lua lib?
I use gcc luac.c -llua -llualib, works.
Related
I'm using an Intel Mac running Catalina 10.15.1
I'm trying to use libsodium using gcc Apple clang version 11.0.0 (clang-1100.0.33.12)
I have both tried to install libsodium via home-brew and manually compile (which was successful), however, when trying to use libsodium I get this error:
Undefined symbols for architecture x86_64:
"_crypto_generichash", referenced from:
_main in sodium-ae2fd0.o
"_sodium_init", referenced from:
_main in sodium-ae2fd0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is the basic code, using libsodium: stable 1.0.18 (bottled), HEAD
1 #include <sodium.h>
2
3 int main(void)
4 {
5
6 sodium_init();
7
8 #define MESSAGE ((const unsigned char *) "Arbitrary data to hash")
9 #define MESSAGE_LEN 22
10
11 unsigned char hash[crypto_generichash_BYTES];
12
13 crypto_generichash(hash, sizeof hash,
14 MESSAGE, MESSAGE_LEN,
15 NULL, 0);
16
17 return 0;
18 }
Any ideas?
The issue is probably not in the libsodium installation, but in the way your example application is compiled.
In order to link a library (besides the C library which is implicitly linked) when compiling a C program, you need to add the -l<library name> flag to the compilation command line:
cc -Wall -W -o example example.c -lsodium
I'm following an online course related to curl. However, I met some problems.
My building statement is:
gcc -Wall web-server.c -o web-server1 -lcurl
This is the code in web-server.c
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
int main(void){
CURL *curl = NULL;
CURLcode res;
curl = curl_easy_init();
curl_easy_setops(curl, CURLOPT_URL, "http://www.google.com");
res = curl_easy_perform(curl);
if (res != CURLE_OK){
print("curl easy perform error res = %d",res);
return 1;
}
curl_easy_cleanup(curl);
return 0;
}
And the error message is:
Undefined symbols for architecture x86_64:
"_curl_easy_setops", referenced from:
_main in web-server-afa9ad.o
"_print", referenced from:
_main in web-server-afa9ad.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thank you guys so much
My operating system is MacOs 10.14.6
My gcc's version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Found CUDA installation: /usr/local/cuda, version unknown
Detailed error message
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library
/Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -
dynamic -arch x86_64 -macosx_version_min 10.14.0 -o web-server
/var/folders/j2/jrqt57vj73s0jc8mjc2mddf40000gn/T/web-server-14b13c.o -lcurl
-lSystem
/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/lib/darwin/libclan
g_rt.osx.a
I am trying to use the tidylib library within my C application. When compiling, I get the following errors:
$ make
rm -f sbo-export
cc sbo-export.c safarilib.c -L/usr/local/lib -lcurl -L/usr/local/Cellar/libtidy/lib -I/usr/local/Cellar/libtidy/include -o sbo-export
Undefined symbols for architecture x86_64:
"_tidyCreate", referenced from:
_safari_init_session in safarilib-c7ab6a.o
"_tidyParseString", referenced from:
_safari_init_session in safarilib-c7ab6a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [default] Error 1
safarilib.c:
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <tidy/tidy.h>
#include <tidy/buffio.h>
#include <curl/curl.h>
#include "safarilib.h"
void usage( char *username, char *password )
{
TidyDoc tdoc = tidyCreate();
char *input = "<html><body><h1>Hello World!</h1></body></html>";
tidyParseString( tdoc, input );
}
Any suggestions?
Further Infos:
For installing libtidy, I did the following:
Downloaded libtidy from http://tidy.sourceforge.net and then
followed the instructions form the file tidy/build/readme.txt
My library is installed here:
/usr/local/Cellar/libtidy
/usr/local/Cellar/libtidy/bin
/usr/local/Cellar/libtidy/bin/tab2space
/usr/local/Cellar/libtidy/bin/tidy
/usr/local/Cellar/libtidy/include
/usr/local/Cellar/libtidy/include/buffio.h
/usr/local/Cellar/libtidy/include/platform.h
/usr/local/Cellar/libtidy/include/tidy.h
/usr/local/Cellar/libtidy/include/tidyenum.h
/usr/local/Cellar/libtidy/lib
/usr/local/Cellar/libtidy/lib/libtidy-0.99.0.dylib
/usr/local/Cellar/libtidy/lib/libtidy.a
/usr/local/Cellar/libtidy/lib/libtidy.dylib
/usr/local/Cellar/libtidy/lib/libtidy.la
From compiler option it's look you have not specified tidylib.
cc sbo-export.c safarilib.c -L/usr/local/lib -lcurl -L/usr/local/Cellar/libtidy/lib -I/usr/local/Cellar/libtidy/include -o sbo-export
Here you need to add -ltidy and probably path by -L .
Some additional info about linking.
I've been having some trouble with the installed version of libsasl2 (Cyrus SASL).
In particular, it seems that the local headers and sasl_version report version 2.1.26, but no symbol is provided for the global function sasl_client_done.
I'm pretty sure I'm supposed to have that symbol because:
It's there in the provided sasl/sasl.h header
The cyrsus sasl NEWS file lists "Implemented sasl_client_done()/sasl_server_done()" as a 2.1.24 feature
It's there everywhere that provides 2.1.26 outside of Yosemite
For a reproduction:
note that the sample below prints
"impl: 'Cyrus SASL', version: 33619994, major: 2, minor: 1, step: 26"
the sample compiles and executes on a linux install with the same library version after uncommenting the code
the uncommented code produces a link error on yosemite
Undefined symbols for architecture x86_64:
"_sasl_client_done", referenced from:
_main in foo-072675.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
invoking the compiler with:
clang -Wall -Werror -lsasl2 -o foo foo.c -v
with clang -v of:
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name foo.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wall -Werror -fdebug-compilation-dir /Users/jcarey/work -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fdiagnostics-show-option -vectorize-slp -o /var/folders/wq/jypwqgv976n0db5l5qxw900r0000gq/T/foo-92054e.o -x c foo.c
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -o foo -lsasl2 /var/folders/wq/jypwqgv976n0db5l5qxw900r0000gq/T/foo-92054e.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_sasl_client_done", referenced from:
_main in foo-92054e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And the code in question:
#include <sasl/sasl.h>
#include <stdio.h>
#include <stdint.h>
int main(int argc, char ** argv) {
const char *impl;
int version;
uint32_t buf;
uint16_t major;
uint8_t minor;
uint8_t step;
sasl_version(&impl, &version);
buf = version;
major = buf >> 24;
minor = (buf << 8) >> 24;
step = (buf << 24) >> 24;
printf("impl: '%s', version: %d, major: %d, minor: %d, step: %d\n", impl, version, major, minor, step);
/*
{
int (* scd)(void);
scd = &sasl_client_done;
printf("sasl_client_done: %p\n", scd);
}
*/
return 0;
}
I'm thinking that something's screwy with the way cyrus sasl got packaged for Yosemite (using a symbol list from Mavericks perhaps?).
As a matter of interest, I just checked with 10.10.4 and I see the symbol is now there:
$ nm /usr/lib/libsasl2.dylib |grep sasl_client_done
000000000000724a T _sasl_client_done
The sample code now works fine (with the commented section now uncommented). The same Cyrus SASL version is still returned though:
impl: 'Cyrus SASL', version: 33619994, major: 2, minor: 1, step: 26
sasl_client_done: 0x7fff8e3dc24a
I have installed XQuartz.
I compiled using g++:
g++ -o -lX11 -I/opt/X11/include window2.cc
Error
Undefined symbols for architecture x86_64:
"_XCreateWindow", referenced from:
_main in window2-dXb9bZ.o
"_XFlush", referenced from:
_main in window2-dXb9bZ.o
"_XMapWindow", referenced from:
_main in window2-dXb9bZ.o
"_XOpenDisplay", referenced from:
_main in window2-dXb9bZ.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If i compile like this:
g++ window2.cc -o window -lX11 -I/opt/X11/include
Error
ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Im sure Xlib.h is in /opt/X11/include
Code:
#include <X11/Xlib.h>
#include <unistd.h>
int main()
{
// Open a display.
Display *d = XOpenDisplay(0);
if ( d )
{
// Create the window
Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 200,
100, 0, CopyFromParent, CopyFromParent,
CopyFromParent, 0, 0);
// Show the window
XMapWindow(d, w);
XFlush(d);
// Sleep long enough to see the window.
sleep(10);
}
return 0;
}
How do I solve this problem ? Thanks in advance
Problem resolved. In case anyone who's interested:
You have to compile like this:
g++ -o window window.cc -I/usr/X11R6/include -L/usr/X11R6/lib -lX11
Try
cc -I /opt/X11/include/ test.c -L /opt/X11/lib -lX11