Linux c++ error: undefined reference to 'dlopen'
You have to link against libdl, add
-ldl
to your linker options
dlopen undefined reference
You have not linked with the dl
library correctly. You are looking for the target_link_libraries
command, using the pre-defined CMake variable CMAKE_DL_LIBS
:
cmake_minimum_required(VERSION 3.14)
project(VulkanTest)
set(CMAKE_CXX_STANDARD 17)
add_executable(VulkanTest main.cpp)
target_link_libraries(VulkanTest ${CMAKE_DL_LIBS})
Undefined reference to 'dlsym' and 'dlopen'
Well, I found the answer, I needed -Wl,--no-as-needed
flag before the -ldl
. I had run across this flag before I asked the question, but apparently mistyped it because it hadn't worked for me.
I don't understand why the flag is needed, but the code does finish linking now.
A SO user here says that it has to do with recent (2013 as of the user's post) versions of gcc linking to --as-needed.
undefined reference to `dlopen'
Move autocheck.cpp so that it is before the libraries in your command. Libraries are only searched for things that need resolving in files that appear before them. So your command should look like this:
gcc autocheck.cpp -I/usr/lib/qt3/include -I/opt/kde3/include/ -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -lqt-mt -ldl -L/usr/lib/qt3/lib64 -o autocheck
Related Topics
Command Not Found in Bash's If-Else Condition When Using [! -D "$Dir"]
Android Studio 3.0 Emulator Does Not Start
Linux, Where Are the Return Codes Stored of System Daemons and Other Processes
Create a Dedicated Folder for Every Zip Files in a Directory and Extract Zip Files
Execute a Shell Script Everyday at Specific Time
Getting Stty: Standard Input: Inappropriate Ioctl for Device When Using Scp Through an Ssh Tunnel
Linux Custom Executable Globally Available
Shell-Init: Error Retrieving Current Directory: Getcwd -- the Usual Fixes Do Not Wor
Execute Command Line and Return Command Output
Execute Script as Another User Whilst Not Being Root
Sed Returns "Sed: Command Garbled"
How to Get Out of 'Screen' Without Typing 'Exit'
How to Map a Hostname *And* a Port with /Etc/Hosts