Where is the library for 'dlsym' - linker

I am getting this linker error:
system/core/libacc/tests/main.cpp:42: error: undefined reference to 'dlsym'
Can you please tell me where is the library on ubuntu 9.10 which contains the library for 'dlsym'?
Thank you.

From the dlsym(3) man page:
#include <dlfcn.h>
....
Link with -ldl.

Related

MingGw error while trying to complie C code

I tried to compile my C code (using mingw) into a EXE file but it just says the following error:
/mingw/lib/libmingw32.a(setargv.o):(.text+0x33): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0x6d2): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0x8b8): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0x900): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0xa25): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0xc15): more undefined references to `__chkstk_ms' follow collect2: ld returned 1 exit status
i ran the command
mingw-get upgrade "mingwer=3.20.*"
and
mingw-get upgrade "mingwer=3.18.*"
but didn't solve the issue
Edit: Command ran
gcc compvisia.c init.c bitboards.c hashkeys.c board.c -o compvisia
Code:
#include "stdio.h"
#include "stdlib.h"
int main() {
printf("hello world");
return 0;
}
Looks like the errors are related to stack protection.
Maybe your system has a mix of different MinGW versions installed, causing linking with mismatching libraries.
MinGW 3 is old, you should really consider moving to MinGW-w64.
You can get a standalone build of MinGW-w64 from https://winlibs.com/ that you can extract somewhere without installing to test if it makes a difference for your source code.
Make sure to use the full path to gcc.exe so you are in fact using the one you think you are using.

Using vscode, why can't I compile when both "iosteam" and "stdio.h" are included?

When I declare and at the same time, vscode can't complie the file and there is the error log:
> Executing task: C:\mingw64\bin\gcc.exe -g d:\CODES\C++\try\main.cpp -o d:\CODES\C++\try\main.exe <
C:\Users\16337\AppData\Local\Temp\ccqDR0fO.o: In function `__tcf_0':
C:/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
C:\Users\16337\AppData\Local\Temp\ccqDR0fO.o: In function `__static_initialization_and_destruction_0':
C:/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status
My code is very simple:
#include <iostream>
#include <stdio.h>
int main()
{
printf("print something");
return 0;
}
Dev-C++ can compile that code properly.
If I delete #include <iostream>, it can be properly compiled.
<iostream> is a standard C++ header, so you need a C++ compiler and linker to use it. gcc is smart enough to compile .cpp files as C++, however it won't link the standard library into your program, hence the undefined references.
You need to use g++, which will link the standard C++ library by default, as Dev-C++ does.

Difficulty in compiling code on OSX terminal that works in Linux environment

I'm taking some working code (that I didn't write and the creator is not around anymore) to try and get it to compile on my Mac (10.9.5) using terminal. I'm getting the following error when compiling (gcc -o code code.c):
Undefined symbols for architecture x86_64:
"_add_history", referenced from:
_rl_gets in talk-c856c6.o
"_read_history", referenced from:
_main in talk-c856c6.o
"_readline", referenced from:
_rl_gets in talk-c856c6.o
"_write_history", referenced from:
_rl_gets in talk-c856c6.o
ld: symbol(s) not found for architecture x86_64
here are all my includes:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <strings.h>
#include <readline/readline.h>
#include <readline/history.h>
I've found here and elsewhere online similar issues and have tried
#include <readline.h>
but get fatal error: 'readline.h' file not found
(same for #include <libedit.dylib>)
I'm a bit of a novice with external libraries so maybe I need to install another one? Is my issue just that the mac needs an additional library installed to use those 5 functions creating errors, or are one of my #includes only for Linux and not for Mac? I thought since both the Mac and the Linux are using Unix it would be the same, but apparently there are subtleties I don't understand.
Thanks in advance.
Did you bass the correct flags to the compiler? Seems like you are not linking against the libedit. Try passing -ledit to the compiler and tell us if that helps.
#include <libedit.dylib>
This is never correct. You can't #include a library, you need to tell the compiler that you want to link against this library when invoking it.

Shared library compilation gcc

I am trying to compile my program that uses the libwebsockets library.
I have downloaded and compiled the libwebsockets on my linux machine and has following directory structure.
/libwebsockets/build/bin/ -> contains the compiled binaries (test-server,test-client etc)
/libwebsockets/build/lib/ -> contains the shared libraries. libwebsockets.so libwebsockets.a libwebsockets.so.5.0.0
/libwebsockets/lib/ -> contains all the header files. eg: libwebsockets.h libwebsockets.c
/libwebsockets/test-server -> contains application programs..(test-server.c test-client.c etc)
Now I created my C program file simple-server.c in
/libwebsockets/test-server directory.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include <signal.h>
#include <libwebsockets.h>
when I try to compile this program:
gcc -L/home/gadre/Desktop/Testing/libwebsockets/build/lib/ -lwebsockets simple-server.c -o s
I get linker error:
simple-server.c:(.text+0x14c): undefined reference to `lwsl_emit_syslog'
simple-server.c:(.text+0x158): undefined reference to `lws_set_log_level'
simple-server.c:(.text+0x16d): undefined reference to `libwebsocket_get_internal_extensions'
simple-server.c:(.text+0x1a5): undefined reference to `libwebsocket_create_context'
simple-server.c:(.text+0x1c4): undefined reference to `_lws_log'
simple-server.c:(.text+0x1e9): undefined reference to `libwebsocket_service'
simple-server.c:(.text+0x209): undefined reference to `libwebsocket_context_destroy'
simple-server.c:(.text+0x21d): undefined reference to `_lws_log'
How to solve this..I tried putting the path in the LD_LIBRARY_PATH as well. but still linker cannot find the shared libraries.
I am able to compile for now... I used following command. with run time link option.
gcc -L/home/gadre/Desktop/Testing/libwebsockets/build/lib -Wl,-rpath=/home/gadre/Desktop/Testing/libwebsockets/build/lib -Wall -o server incr_server.c -lwebsockets
I don't know specifics but it works for now

Why I cannot use my GMP library in Linux

I was writing some codes in linux using c. When tried to compiled, I got this response:
/tmp/ccW8mQDx.o: In function `main':
server.c:(.text+0x3e): undefined reference to `__gmpz_set_str'
server.c:(.text+0x5a): undefined reference to `__gmpz_set_str'
In fact, all the functions of gmp that I used couldn't be found.
Seems there are some problem with the gmp.
Could anyone please tell me how to solve it? Thanks in advance!
The undefined reference errors appear when you forgot to link your application with the library, GMP in this case. Read in the documentation of GMP the name of the library to link and use the -l compiler switch to link it.
Have you tried -lgmp ?
If that doesn't work you can look for the libgmp.a library:
cd /usr
find . -name libgmp.a -print
Add -l option ,when you compile the code. It will add the library files.

Resources