I have included the openssl/md5.h in my source.
#include <openssl/md5.h>
This is my (part of) my code:
char *pf_generate_pfdhr_string(int firstfree, int numpages)
{
const int md5_digest_len = 16;
char hash[md5_digest_len];
MD5_CTX md5_ctx;
MD5_Init(&md5_ctx);
int hdr_arr[2] = {firstfree, numpages};
MD5_Update(&md5_ctx, hdr_arr, 2*sizeof(int));
MD5_Final(hash, &md5_ctx);
return hash;
}
And this is my output
ranlib build/libpf.a
cc -g -O2 -Wall -Wextra -Isrc -rdynamic tests/pf_tests.c build/libpf.a -o tests/pf_tests
Undefined symbols for architecture x86_64:
"_MD5_Final", referenced from:
_pf_generate_pfdhr_string in libpf.a(pf.o)
"_MD5_Init", referenced from:
_pf_generate_pfdhr_string in libpf.a(pf.o)
"_MD5_Update", referenced from:
_pf_generate_pfdhr_string in libpf.a(pf.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: *** [tests/pf_tests] Error 1
I have included the header file so the compiler knows the function exists. However, it seems unable to find the object files for the md5 library. How can I include it in my build?
If I am using Make, what is the best way to do so?
Thank you.
Check the documentation for your platform. It may be -lcrypto -lssl. It may not be. If your platform supports pkg-config, use pkg-config --libs openssl.
Related
Today I installed the Allegro game programming library for C and I’ve tried to include one of the header files but when I try to execute gcc -I./include example.c -o a.exe in the terminal, I keep on getting this error:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: __al_mangled_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any ideas? I installed Allegro 5 using the instructions here: https://wiki.allegro.cc/index.php?title=Install_Allegro5_From_GIT/OSX
example.c code:
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, const char *argv[]){
puts(“Hello, world!”);
return 0;
}
You need to link your executable to Allegro.
According to the FAQ, you should add -lallegro to your compile command, or -lallegro -lallegro_main on OSX
You may need other flags, and Allegro 5 uses pkg-config instead of allegro-config, so do pkg-config allegro-5.0 allegro_main-5.0 --cflags --libs to find out.
You can combine this into a compiler command by using backticks, e.g.
$CC -W -Wall `pkg-config allegro-5.0 allegro_main-5.0 --cflags --libs` foo.c -o foo.exe
Can I use for example
gcc -o -S output.s abs.c
to generate an assembly file with name output.s? It seems like I can't. When I try to do that, I got following error message.
Undefined symbols for architecture x86_64: "_main", referenced from:
implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit
code 1 (use -v to see invocation)
I do not intend to use the linker, just try to examine the assembly code.
-o must be followed by the name of the output file. So, this would work:
gcc -S abc.c -o output.s
I have 3 files, main.c, lists.c, and lists.h.
Im trying to write a Makefile with all the files are in the same directory:
maman21: lists.c lists.h main.c
gcc -g -Wall -ansi main.c -o maman21 -lm
going to the folder through terminal and using make shows me this message:
gcc -g -Wall -ansi main.c -o maman21 -lm
Undefined symbols for architecture x86_64: "_linkedListWay",
referenced from:
_main in main-C9dUT4.o "_reallocWay", referenced from:
_main in main-C9dUT4.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: *** [maman21] Error 1
reallocWay and linkedListWay are to functions I'm using in the file.
Thank you for your help.
You've failed to include the lists.c file in the compiler invocation so it doesn't get built.
It should be:
CFLAGS=-g -Wall -ansi
LDLIBS=-lm
maman21: main.o lists.o
main.o: main.c
lists.o: lists.c lists.h
The above uses implicit Makefile rules, it "knows" how to convert a C file to an object (.o) file.
Also, is it normal for Clang to be called gcc?
I'm trying to compile the following libusb snippet on my Mac:
#include <stdio.h>
#include <stdlib.h>
#include <libusb.h>
int main(void) {
libusb_device **devices;
ssize_t device_count = 0;
device_count = libusb_get_device_list(NULL, &devices);
printf("%d devices found\n", (int)device_count);
return EXIT_SUCCESS;
}
I have libusb installed via Homebrew.
I'm getting the following error during compilation:
ld: symbol(s) not found for architecture x86_64
The full compiler output is as follows:
22:28:24 **** Incremental Build of configuration Debug for project libusb ****
make all
Building file: ../src/libusb.c
Invoking: Cross GCC Compiler
gcc -I/usr/local/Cellar/libusb/1.0.9/include/libusb-1.0/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/libusb.d" -MT"src/libusb.d" -o "src/libusb.o" "../src/libusb.c"
Finished building: ../src/libusb.c
Building target: libusb
Invoking: Cross GCC Linker
gcc -o "libusb" ./src/libusb.o
Undefined symbols for architecture x86_64:
"_libusb_get_device_list", referenced from:
_main in libusb.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: *** [libusb] Error 1
22:28:24 Build Finished (took 119ms)
I understand the problem is to do with the linker not finding the libusb library, right? How do I tell the compiler where that is in Eclipse CDT?
As we worked out in all the comments the link command that worked is
gcc -L/usr/local/Cellar/libusb/1.0.9/lib -o "libusb_example" ./src/libusb_example.o -lusb1.0
I am trying to compile a simple gearman worker on C. I use mac. Here is the code:
#include <libgearman/gearman.h>
int main(void) {
gearman_worker_st worker;
gearman_worker_create(&worker);
gearman_worker_add_server(&worker, "localhost", 4730);
return 0;
}
When I try to compile it with:
#gcc test.c
Undefined symbols for architecture x86_64:
"_gearman_worker_add_server", referenced from:
_main in ccLUuf8y.o
"_gearman_worker_create", referenced from:
_main in ccLUuf8y.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I know I have to link gcc with gearman but when try:
#gcc test.c -lgearman
ld: library not found for -lgearman
collect2: ld returned 1 exit status
Any ideas?
maybe your need to define the lib path, like
-L/usr/lib/, use your libgearman.a stored path to substitute -L/usr/lib/
maybe your need to define the "include path" and the "lib path",
for example,
the head file "libgearman/gearman.h" in the /usr/local,
the library libgearman.so in the /usr/local/libgearman/lib
the compile command like,
gcc -I/usr/local -L/usr/local/libgearman/lib test.c -lgearman
As stated here, you have to link it with -lgearman
gcc test.c -lgearman