I have this c++ program:
#include <iostream>
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
namespace hrean::ffmpeg
{
namespace detail
{
}//namespace detail
void testFFmpeg()
{
AVFormatContext *avFormatContext = avformat_alloc_context();
//I can comment out the rest of the function, the error is the same
} //testFFmpeg()
} //namespace hrean::ffmpeg
int main(int argc, char **argv)
{
try
{
hrean::ffmpeg::testFFmpeg();
}
catch(const std::runtime_error& e)
{
std::cerr << "Error! " << e.what() << '\n';
return -1;
}
catch(...)
{
std::cerr << "Unknown error\n";
return -1;
}
return 0;
}
The CMakeLists.txt for this is:
cmake_minimum_required(VERSION 3.13)
project(hrean)
add_subdirectory(lib/ffmpeg-module)
message("[temp] FFMPEG_INCLUDE_DIRS = ${FFMPEG_INCLUDE_DIRS}")
message("[temp] FFMPEG_LIBRARIES = ${FFMPEG_LIBRARIES}")
add_executable(hrean-app src/main.cpp)
target_include_directories(hrean-app PUBLIC ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(hrean-app PUBLIC ${FFMPEG_LIBRARIES})
The CMakeLists.txt for lib/ffmpeg-module contains only
find_package(FFmpeg REQUIRED MODULE)
The CMake output is:
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for module 'libavcodec'
-- Found libavcodec, version 60.2.100
-- Checking for module 'libavformat'
-- Found libavformat, version 60.2.100
-- Checking for module 'libavdevice'
-- Found libavdevice, version 60.0.100
-- Checking for module 'libavutil'
-- Found libavutil, version 58.1.100
-- Checking for module 'libavfilter'
-- Found libavfilter, version 9.1.100
-- Checking for module 'libswscale'
-- Found libswscale, version 7.0.100
-- Checking for module 'libpostproc'
-- Found libpostproc, version 57.0.100
-- Checking for module 'libswresample'
-- Found libswresample, version 4.9.100
-- Found FFmpeg: /home/serban/ffmpeg_build/lib/libavcodec.a;/home/serban/ffmpeg_build/lib/libavformat.a;/home/serban/ffmpeg_build/lib/libavutil.a
[temp] FFMPEG_INCLUDE_DIRS = /home/serban/ffmpeg_build/include
[temp] FFMPEG_LIBRARIES = /home/serban/ffmpeg_build/lib/libavcodec.a;/home/serban/ffmpeg_build/lib/libavformat.a;/home/serban/ffmpeg_build/lib/libavutil.a
-- Configuring done
-- Generating done
-- Build files have been written to: /home/serban/Work/hrean/build
When I run make, I get the following errors. The problem is, this worked perfectly yesterday and I changed nothing. I create a new Ubuntu virtual machine, everything fresh and I still get the same problem. The output is 1000+ lines long, here is some of it:
[ 50%] Building CXX object CMakeFiles/hrean-app.dir/src/main.cpp.o
[100%] Linking CXX executable hrean-app
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(amvenc.o): in function `amv_write_packet':
/home/serban/ffmpeg/libavformat/amvenc.c:356: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:357: undefined reference to `av_packet_ref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(amvenc.o): in function `amv_deinit':
/home/serban/ffmpeg/libavformat/amvenc.c:209: undefined reference to `av_packet_free'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(amvenc.o): in function `amv_init':
/home/serban/ffmpeg/libavformat/amvenc.c:111: undefined reference to `avcodec_get_name'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:117: undefined reference to `avcodec_get_name'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:188: undefined reference to `av_new_packet'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:196: undefined reference to `av_packet_alloc'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_close':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1413: undefined reference to `av_packet_free'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_single_payload':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1119: undefined reference to `av_new_packet'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_packet':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1388: undefined reference to `av_packet_move_ref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `reset_packet':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1030: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_deinterleave':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1313: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/asfdec_o.c:1314: undefined reference to `av_packet_from_data'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_replicated_data':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1043: undefined reference to `av_new_packet'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_timestamp':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1463: undefined reference to `av_packet_alloc'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `reset_packet':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1030: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_timestamp':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1512: undefined reference to `av_packet_unref'
Any idea how to debug this?
Later edit:
This is the find script I am using: FindFFmpeg.cmake
I changed the way I link to the libraries, this way causes the least amount of errors:
set(ORDERED_FFMPEG_LIBRARIES ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${AVUTIL_LIBRARIES})
message("[temp] ORDERED_FFMPEG_LIBRARIES=${ORDERED_FFMPEG_LIBRARIES}")
add_executable(hrean-app src/main.cpp)
target_include_directories(hrean-app PUBLIC ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(hrean-app PUBLIC ${ORDERED_FFMPEG_LIBRARIES})
The errors are similar, but they seem to point to other locations:
[100%] Linking CXX executable hrean-app
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(mov.o): in function `mov_read_cmov':
/home/serban/ffmpeg/libavformat/mov.c:5578: undefined reference to `uncompress'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `swf_read_packet':
/home/serban/ffmpeg/libavformat/swfdec.c:393: undefined reference to `uncompress'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `swf_read_header':
/home/serban/ffmpeg/libavformat/swfdec.c:161: undefined reference to `inflateInit_'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `zlib_refill':
/home/serban/ffmpeg/libavformat/swfdec.c:134: undefined reference to `inflate'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `swf_read_close':
/home/serban/ffmpeg/libavformat/swfdec.c:557: undefined reference to `inflateEnd'
Do I have to link to anything else?
Regards,
Serban
Not far ago ffmpeg became depended off zlib.
See this include.
You may build ffmpeg without zlib
Or you may install zlib and link with it:
find_library(ZLIB NAMES z zlib REQUIRED)
target_link_libraries(hrean-app PRIVATE ${ZLIB})
Related
I've been struggling with this for longer than I care to admit and would really appreciate some help.
I'm trying to do a project which involves building a linker and scheduler, and thought if I could use some of the functionality that's already been build into LLVM that would be great. I'm using LLVM 10. To get started I did some reading and tried to build this example. Because I plan on embedding LLVM into another project, used this as a reference for 'how to build' the example (see below). I figured the dependencies are just the components from the example CMakeLists.txt.
If I'm not mistaken, I'm getting a linker error and that the component list is the problem, but I'm struggling to resolve it. The way it seems LLVM does linking is by mapping a component name to an library file, but since I don't know which missing library might be causing it I'm stuck. Also, I don't know what llvm_libs is, but adding it to the component list seemed to resolve some of the linker errors I was getting originally. Also also, changing the order of the component list will give me different amounts of errors, which absolutely confounds me.
CMakeLists.txt
cmake_minimum_required(VERSION 3.13.4)
project(HowToUseJIT)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# Set your project compile flags.
# E.g. if using the C++ header files
# you will need to enable C++11 support
# for your compiler.
message(STATUS "INCLUDE ${LLVM_INCLUDE_DIRS}")
include_directories(${LLVM_INCLUDE_DIRS})
message(STATUS "DEFINITIONS ${LLVM_DEFINITIONS}\n${LLVM_DEFINITIONS_LIST}")
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
# Now build our tools
add_executable(HowToUseJIT HowToUseJIT.cpp)
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core interpreter nativecodegen executionengine)
# Link against LLVM libraries
message(STATUS "LIBS ${llvm_libs}")
target_link_libraries(HowToUseJIT ${llvm_libs})
Then from a subdir I run
$ cmake ../
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jeremy_arsenault/Documents/random/llvm_examples/HowToUseJIT/build
$ cmake --build .
[ 50%] Building CXX object CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o
[100%] Linking CXX executable HowToUseJIT
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `main':
HowToUseJIT.cpp:(.text+0x4b7): undefined reference to `llvm::EngineBuilder::EngineBuilder(std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >)'
/usr/bin/ld: HowToUseJIT.cpp:(.text+0x4dc): undefined reference to `llvm::EngineBuilder::~EngineBuilder()'
/usr/bin/ld: HowToUseJIT.cpp:(.text+0x693): undefined reference to `llvm::EngineBuilder::~EngineBuilder()'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::EngineBuilder::create()':
HowToUseJIT.cpp:(.text._ZN4llvm13EngineBuilder6createEv[_ZN4llvm13EngineBuilder6createEv]+0x18): undefined reference to `llvm::EngineBuilder::selectTarget()'
/usr/bin/ld: HowToUseJIT.cpp:(.text._ZN4llvm13EngineBuilder6createEv[_ZN4llvm13EngineBuilder6createEv]+0x2a): undefined reference to `llvm::EngineBuilder::create(llvm::TargetMachine*)'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::IRBuilderDefaultInserter::IRBuilderDefaultInserter()':
HowToUseJIT.cpp:(.text._ZN4llvm24IRBuilderDefaultInserterC2Ev[_ZN4llvm24IRBuilderDefaultInserterC5Ev]+0xf): undefined reference to `vtable for llvm::IRBuilderDefaultInserter'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::InitializeNativeTarget()':
HowToUseJIT.cpp:(.text._ZN4llvm22InitializeNativeTargetEv[_ZN4llvm22InitializeNativeTargetEv]+0x9): undefined reference to `LLVMInitializeX86TargetInfo'
/usr/bin/ld: HowToUseJIT.cpp:(.text._ZN4llvm22InitializeNativeTargetEv[_ZN4llvm22InitializeNativeTargetEv]+0xe): undefined reference to `LLVMInitializeX86Target'
/usr/bin/ld: HowToUseJIT.cpp:(.text._ZN4llvm22InitializeNativeTargetEv[_ZN4llvm22InitializeNativeTargetEv]+0x13): undefined reference to `LLVMInitializeX86TargetMC'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::~IRBuilder()':
HowToUseJIT.cpp:(.text._ZN4llvm9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEED2Ev[_ZN4llvm9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEED5Ev]+0x1c): undefined reference to `llvm::IRBuilderDefaultInserter::~IRBuilderDefaultInserter()'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::IRBuilderFolder::IRBuilderFolder()':
HowToUseJIT.cpp:(.text._ZN4llvm15IRBuilderFolderC2Ev[_ZN4llvm15IRBuilderFolderC5Ev]+0xf): undefined reference to `vtable for llvm::IRBuilderFolder'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::ConstantFolder::ConstantFolder()':
HowToUseJIT.cpp:(.text._ZN4llvm14ConstantFolderC2Ev[_ZN4llvm14ConstantFolderC5Ev]+0x1f): undefined reference to `vtable for llvm::ConstantFolder'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::IRBuilder(llvm::BasicBlock*, llvm::MDNode*, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >)':
HowToUseJIT.cpp:(.text._ZN4llvm9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEEC2EPNS_10BasicBlockEPNS_6MDNodeENS_8ArrayRefINS_17OperandBundleDefTIPNS_5ValueEEEEE[_ZN4llvm9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEEC5EPNS_10BasicBlockEPNS_6MDNodeENS_8ArrayRefINS_17OperandBundleDefTIPNS_5ValueEEEEE]+0xbb): undefined reference to `llvm::IRBuilderDefaultInserter::~IRBuilderDefaultInserter()'
/usr/bin/ld: CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o: in function `llvm::ConstantFolder::~ConstantFolder()':
HowToUseJIT.cpp:(.text._ZN4llvm14ConstantFolderD2Ev[_ZN4llvm14ConstantFolderD5Ev]+0x13): undefined reference to `vtable for llvm::ConstantFolder'
/usr/bin/ld: HowToUseJIT.cpp:(.text._ZN4llvm14ConstantFolderD2Ev[_ZN4llvm14ConstantFolderD5Ev]+0x26): undefined reference to `llvm::IRBuilderFolder::~IRBuilderFolder()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/HowToUseJIT.dir/build.make:91: HowToUseJIT] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/HowToUseJIT.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
If anyone knows what my problem is, has any advice on running these LLVM examples, or knows of any resources that might better my understanding of wtf is happening I will be eternally grateful :). Thanks in advance for any help!
Edit 1: I tried the same procedure on some other examples to see what would happen. On Fibonacci everything build fine then seg faulted on runtime. On ModuleMaker I build fails on undefined reference to main... I'm really bungling something up here I just don't know what.
Edit 2: Thank you for the responses. I'm currently attempting to get everything to build correctly using Alexs advice. Simply using the CMakeLists.txt and building using Ninja did not work :( (I updated the build process outputs above). I was getting similar errors as before. Since Alex mentioned that he needed to use a different version of llvm header files, I figured I'd just build an updated version from source - but LLVM bested me once again. The build from source procedure in the README bombs on every release version I try (I'm running Ubuntu 20.04 lts). I'm starting to think my best bet is to just cherry-pick files and hack something together myself because this is getting to be too much of a headache.
Edit 3: I got it working :)
Solution
Everything ran and built fine when I updated to the newest version of LLVM. I ran into a lot of build problems on Ubuntu 20.04 lts that were a product of missing dependencies. This kind soul posted all the deps he needed to install in order to build llvm without errors.
So the following build worked for me and should hopefully be a model for you re: how to use CMake...
cmake_minimum_required(VERSION 3.22)
project(test)
# Find LLVM and the components we require.
find_package(LLVM 10 REQUIRED)
llvm_map_components_to_libnames(
LLVM_LIBRARIES
Core
ExecutionEngine
Interpreter
MC
MCJIT
Support
nativecodegen
)
# Create a wrapper for the LLVM components we need in this
# project. This will allow us to link it to multiple targets
# without duplicating a lot of code. It's too bad that LLVM
# doesn't provide anything like this.
add_library(test::LLVM INTERFACE IMPORTED)
target_include_directories(test::LLVM INTERFACE ${LLVM_INCLUDE_DIRS})
target_compile_definitions(test::LLVM INTERFACE ${LLVM_DEFINITIONS})
target_link_libraries(test::LLVM INTERFACE ${LLVM_LIBRARIES})
# Create our actual executable and link LLVM to it.
add_executable(HowToUseJIT HowToUseJIT.cpp)
target_link_libraries(HowToUseJIT PRIVATE test::LLVM)
Notice the following:
LLVM does not provide its own imported targets (bad)
We therefore create our own imported target to wrap it, test::LLVM.
We add the MC and MCJIT components to the list of components.
We assign the package-provided variables and computed list of libraries to the relevant properties of our imported target.
We always call target_link_libraries with a visibility specifier (they are PRIVATE, INTERFACE, and PUBLIC. Omitting it is none of the above.)
We state the version number of LLVM we require in the find_package call and omit the unnecessary CONFIG argument. Every major version of LLVM breaks the API in significant ways.
At the terminal, I now see:
$ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/build
$ cmake --build build/ --verbose
[1/2] /usr/bin/c++ -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -isystem /usr/lib/llvm-10/include -O3 -DNDEBUG -MD -MT CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o -MF CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o.d -o CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o -c /path/to/HowToUseJIT.cpp
[2/2] : && /usr/bin/c++ -O3 -DNDEBUG CMakeFiles/HowToUseJIT.dir/HowToUseJIT.cpp.o -o HowToUseJIT /usr/lib/llvm-10/lib/libLLVMInterpreter.a /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/llvm-10/lib/libLLVMMCJIT.a /usr/lib/llvm-10/lib/libLLVMExecutionEngine.a /usr/lib/llvm-10/lib/libLLVMRuntimeDyld.a /usr/lib/llvm-10/lib/libLLVMX86CodeGen.a /usr/lib/llvm-10/lib/libLLVMAsmPrinter.a /usr/lib/llvm-10/lib/libLLVMDebugInfoDWARF.a /usr/lib/llvm-10/lib/libLLVMCFGuard.a /usr/lib/llvm-10/lib/libLLVMGlobalISel.a /usr/lib/llvm-10/lib/libLLVMSelectionDAG.a /usr/lib/llvm-10/lib/libLLVMCodeGen.a /usr/lib/llvm-10/lib/libLLVMTarget.a /usr/lib/llvm-10/lib/libLLVMBitWriter.a /usr/lib/llvm-10/lib/libLLVMScalarOpts.a /usr/lib/llvm-10/lib/libLLVMAggressiveInstCombine.a /usr/lib/llvm-10/lib/libLLVMInstCombine.a /usr/lib/llvm-10/lib/libLLVMTransformUtils.a /usr/lib/llvm-10/lib/libLLVMAnalysis.a /usr/lib/llvm-10/lib/libLLVMProfileData.a /usr/lib/llvm-10/lib/libLLVMX86Desc.a /usr/lib/llvm-10/lib/libLLVMObject.a /usr/lib/llvm-10/lib/libLLVMBitReader.a /usr/lib/llvm-10/lib/libLLVMCore.a /usr/lib/llvm-10/lib/libLLVMRemarks.a /usr/lib/llvm-10/lib/libLLVMBitstreamReader.a /usr/lib/llvm-10/lib/libLLVMMCParser.a /usr/lib/llvm-10/lib/libLLVMTextAPI.a /usr/lib/llvm-10/lib/libLLVMX86Utils.a /usr/lib/llvm-10/lib/libLLVMMCDisassembler.a /usr/lib/llvm-10/lib/libLLVMMC.a /usr/lib/llvm-10/lib/libLLVMBinaryFormat.a /usr/lib/llvm-10/lib/libLLVMDebugInfoCodeView.a /usr/lib/llvm-10/lib/libLLVMDebugInfoMSF.a /usr/lib/llvm-10/lib/libLLVMX86Info.a /usr/lib/llvm-10/lib/libLLVMSupport.a -lz -lrt -ldl -ltinfo -lpthread -lm /usr/lib/llvm-10/lib/libLLVMDemangle.a && :
$ ./build/HowToUseJIT
We just constructed this LLVM module:
; ModuleID = 'test'
source_filename = "test"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
define i32 #add1(i32 %AnArg) {
EntryBlock:
%0 = add i32 1, %AnArg
ret i32 %0
}
define i32 #foo() {
EntryBlock:
%0 = tail call i32 #add1(i32 10)
ret i32 %0
}
Running foo: Result: 11
Note: I had to use the sources for HowToUseJIT from a more recent LLVM release (the one from 13.0.0) because the old one has a segfault on some systems. However, that bug is unrelated to the build process.
I am using dpdk-stable-19.11.3, and the NIC is Mellaonx Connect5-X. The project's main function is written in C++, but all other functions it calls are written in C. I use cmake to manage my project. I packed all C code to a static library. Without dpdk, it's fine. After adding dpdk, the CMakeLists.txt seems missing some libs. It compiled successfully. But when running the executable file, it returns "open file error". Then I added libs rte_pmd_mlx5 and ibverbs. The errors occur when running command make.
➜ build git:(master) ✗ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hewen/demo/build
[ 83%] Built target mylib
[ 91%] Linking CXX executable demo
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_open_device':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:830: undefined reference to `mlx5dv_open_device'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_port_query':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:1030: undefined reference to `mlx5dv_query_devx_port'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_qp_query':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:1012: undefined reference to `mlx5dv_devx_qp_query'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_umem_dereg':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:999: undefined reference to `mlx5dv_devx_umem_dereg'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_umem_reg':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:984: undefined reference to `mlx5dv_devx_umem_reg'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_get_async_cmd_comp':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:969: undefined reference to `mlx5dv_devx_get_async_cmd_comp'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_query_async':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:950: undefined reference to `mlx5dv_devx_obj_query_async'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_destroy_cmd_comp':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:937: undefined reference to `mlx5dv_devx_destroy_cmd_comp'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_create_cmd_comp':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:925: undefined reference to `mlx5dv_devx_create_cmd_comp'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_general_cmd':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:910: undefined reference to `mlx5dv_devx_general_cmd'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_modify':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:893: undefined reference to `mlx5dv_devx_obj_modify'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_query':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:876: undefined reference to `mlx5dv_devx_obj_query'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_destroy':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:863: undefined reference to `mlx5dv_devx_obj_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_devx_obj_create':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:847: undefined reference to `mlx5dv_devx_obj_create'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_destroy_flow_matcher':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:815: undefined reference to `mlx5dv_dr_matcher_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_destroy_flow':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:804: undefined reference to `mlx5dv_dr_rule_destroy'
...
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:517: undefined reference to `mlx5dv_create_wq'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dv_create_cq':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:502: undefined reference to `mlx5dv_create_cq'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_destroy_domain':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:489: undefined reference to `mlx5dv_dr_domain_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_domain':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:476: undefined reference to `mlx5dv_dr_domain_create'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_destroy_flow_tbl':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:463: undefined reference to `mlx5dv_dr_table_destroy'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_tbl':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:450: undefined reference to `mlx5dv_dr_table_create'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_pop_vlan':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:439: undefined reference to `mlx5dv_dr_action_create_pop_vlan'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_push_vlan':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:426: undefined reference to `mlx5dv_dr_action_create_push_vlan'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_drop':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:414: undefined reference to `mlx5dv_dr_action_create_drop'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_dest_port':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:397: undefined reference to `mlx5dv_dr_action_create_dest_ib_port'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_dr_create_flow_action_dest_flow_tbl':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:385: undefined reference to `mlx5dv_dr_action_create_dest_table'
/home/hewen/dpdk-stable-19.11.3/x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5.a(mlx5_glue.o): In function `mlx5_glue_destroy_flow_action':
/home/hewen/dpdk-stable-19.11.3/drivers/net/mlx5/mlx5_glue.c:190: undefined reference to `mlx5dv_dr_action_destroy'
collect2: error: ld returned 1 exit status
CMakeFiles/demo.dir/build.make:95: recipe for target 'demo' failed
make[2]: *** [demo] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/demo.dir/all' failed
Is there any libs I missed? This is my CMakeLists.txt.
cmake_minimum_required(VERSION 3.10)
project(myPJ LANGUAGES C CXX)
find_package(Threads REQUIRED)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_FLAGS "-msse4.2")
option(DEBUG "add complie options for gdb" ON)
set(RTE_SDK /home/hewen/dpdk-stable-19.11.3)
set(RTE_TARGET x86_64-native-linuxapp-gcc)
include_directories(${RTE_SDK}/${RTE_TARGET}/include)
link_directories(${RTE_SDK}/${RTE_TARGET}/lib)
include_directories(./tools)
link_directories("./tools/")
add_definitions(-pthread)
if(DEBUG)
add_compile_options(-g -O0)
endif()
add_definitions(-DBUCKET_CLEANER)
add_definitions(-DCOLLECT_STATS -DTABLE_COLLECT_STATS -DLOG_COLLECT_STATS)
add_definitions(-DVERBOSE)
add_library(mylib STATIC a.c b.c c.c d.c)
add_executable(demo main.cpp)
target_link_libraries(demo PRIVATE mylib)
target_link_libraries(demo PRIVATE libxxhash.so)
target_link_libraries(demo PRIVATE Threads::Threads)
target_link_libraries(demo PRIVATE
-Wl,--whole-archive
rte_ethdev
rte_eal
rte_mempool
rte_pmd_mlx5
ibverbs
rte_pmd_e1000
rte_pmd_i40e
rte_pmd_ixgbe
rte_pmd_virtio
rte_pmd_vmxnet3_uio
rte_hash
rte_kvargs
rte_bus_pci
rte_pci
rte_bus_vdev
rte_mbuf
rte_ring
rte_net
pthread
dl
-Wl,--no-whole-archive
numa
rt
pcap
m
)
If using custom Makefile or CMakeLists.txt, one has to ensure the following
DPDK is built with appropriate MXL5 PMD
For DPDK Makefile is used, libraries added to build path are
EXTRA_CFLAGS=-I/path/to/rdma-core/build/include
EXTRA_LDFLAGS=-L/path/to/rdma-core/build/lib
PKG_CONFIG_PATH=/path/to/rdma-core/build/lib/pkgconfig
Cross check and verify example code like l2fwd and skeleton works.
note: as mentioned in the comment it is useful to check
https://doc.dpdk.org/guides/nics/mlx5.html
check the build flags for example/l2fwde in build folder too.
[EDIT-1] as per the update in comment, the problem is resolved by including mxl5 library to CMakeLists.txt.
I've been trying to compile an open-source C++ project Typesense, which has this list of dependencies:
Snappy
zlib
OpenSSL (>=1.0.2)
curl
ICU
brpc
braft
Host and target OS is Debian Linux. Compilation is handled via cmake->make sequence of commands. I was able to install some of dependencies through a package manager (I believe they reside in /usr/lib then), the last two I had to compile on my own, I put them in /usr/local/lib.
All the dependencies were successfully compiled, and the target project compiled too.
When it comes to linking stage, I get numerous errors like
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-easy.o): in function `global_init':
(.text+0x94): undefined reference to `libssh2_init'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-http2.o): in function `on_header':
(.text+0x6c): undefined reference to `nghttp2_session_get_stream_user_data'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-socks_gssapi.o): in function `check_gss_err.part.0':
(.text+0x57): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x77): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x9b): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xcf): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xef): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x112): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x17e): undefined reference to `gss_release_buffer'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-curl_rtmp.o): in function `rtmp_connect':
(.text+0xd4): undefined reference to `RTMP_Connect1'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-openldap.o): in function `ldap_connecting':
(.text+0x111): undefined reference to `ldap_result'
There is at least a hundred of such errors. I'm not at all proficient with Linux and complex building of projects. How do I possibly fix linking errors for libraries that I just downloaded through a package manager?
EDIT: Libraries, that cmake seems to link against at the end:
braft;
brpc;
/usr/lib/x86_64-linux-gnu/libleveldb.a;
glog;
h2o-evloop;
iconv;
/usr/lib/x86_64-linux-gnu/libcurl.a;
for;
/usr/lib/x86_64-linux-gnu/libicui18n.a;
/usr/lib/x86_64-linux-gnu/libicuuc.a;
/usr/lib/x86_64-linux-gnu/libicudata.a;
rocksdb;
/usr/lib/x86_64-linux-gnu/libsnappy.a;
/usr/lib/x86_64-linux-gnu/libz.a;
rt;
/usr/lib/x86_64-linux-gnu/libssl.a;
/usr/lib/x86_64-linux-gnu/libcrypto.a;
pthread;
dl;
-static-libgcc;
-static-libstdc++;
gflags_shared;
/usr/lib/x86_64-linux-gnu/libprotobuf.a;
-lpthread
Your dependency list is incomplete. It only includes immediate dependencies.
Your version of libcurl is built with ssh, gssapi, nghttp2, ldap, rtmp and possibly other goodies, none of which you are linking against. You are using static linking, and static libraries do not have a built in concept of dependencies. This means you have to manually include all the non-immediate dependencies in your build command. You can get the impression of how many more libraries you need to include by executing this command
ldd /path/to/your/libcurl.so
and observing the list of dependencies your libcurl has.
The same thing may be true about other libraries you use.
One way to resolve the issue is to use dynamic linking. This way you just link to immediate dependencies, and they know their dependencies.
I am currently new to C++ and CMake and I am trying to get the code for a project to build natively on windows 10: https://github.com/Marius-Juston/CarND-Path-Planning-Project . This is part of a Udacity Nanodegree and it contains starting scripts such as the main.cpp which is dependant on uWebSockets, checkout e94b6e1, in order to communicate with a Unity App. This in itself is dependant on OpenSSL, ZLib, and XMRigs-deps. They have install/setup files for Linux and mac but not for windows.
I have downloaded each of the source files uWebsockets (in my source directory), OpenSSL-Win64 (in Program Files), xmrig-deps-4.1 (in Program Files) and zlib-1.2.11 (in Program Files, this does not include a include and lib folder), and included the directories in my CMakeList.txt; however, I am getting:
C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lzlib-1.2.11
C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lOpenSSL-Win64
C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lxmrig-deps-4.1
C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -luWebSockets
collect2.exe: error: ld returned 1 exit status
From the documentation it seems that the libraries need to contain a *.a or *.so; however, none of the source files contain that. When I try to exclude these libraries from CMakeList I get this error:
CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `operator()':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:113: undefined reference to `uWS::WebSocket<true>::send(char const*, unsigned long long, uWS::OpCode, void (*)(void*, void*, bool, void*), void*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:118: undefined reference to `uWS::WebSocket<true>::send(char const*, unsigned long long, uWS::OpCode, void (*)(void*, void*, bool, void*), void*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:129: undefined reference to `uWS::WebSocket<true>::close(int, char const*, unsigned long long)'
CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:59: undefined reference to `uWS::Group<true>::onMessage(std::function<void (uWS::WebSocket<true>, char*, unsigned long long, uWS::OpCode)>)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:123: undefined reference to `uWS::Group<true>::onConnection(std::function<void (uWS::WebSocket<true>, uWS::HttpRequest)>)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:127: undefined reference to `uWS::Group<true>::onDisconnection(std::function<void (uWS::WebSocket<true>, int, char*, unsigned long long)>)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:134: undefined reference to `uWS::Hub::listen(int, uS::TLS::Context, int, uWS::Group<true>*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:134: undefined reference to `uS::TLS::Context::~Context()'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:141: undefined reference to `uS::Node::run()'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/main.cpp:134: undefined reference to `uS::TLS::Context::~Context()'
CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `uWS::Hub::Hub(int, bool)':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uS::Node::Node(int, int, int, bool)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uWS::Group<true>::Group(int, uWS::Hub*, uS::NodeData*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uWS::Group<false>::Group(int, uWS::Hub*, uS::NodeData*)'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:48: undefined reference to `inflateInit2_'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:47: undefined reference to `uS::Node::~Node()'
CMakeFiles\path_planning.dir/objects.a(main.cpp.obj): In function `uWS::Hub::~Hub()':
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:53: undefined reference to `inflateEnd'
C:/Users/mariu/Documents/GitHub/CarND-Path-Planning-Project/src/uWebSockets/src/Hub.h:52: undefined reference to `uS::Node::~Node()'
collect2.exe: error: ld returned 1 exit status
I have managed to get the code to work on Windows with the Linux Subsystem; however, this is not what I want because I am unable to use my IDE, CLion, to debug/run the program through the Linux subsystem. How would I change the CMakeLists.txt to get the program to compile and run in Windows 10?
Here is my GNU:
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
And my CMakeLists.txt:
project(Path_Planning)
cmake_minimum_required(VERSION 3.5)
add_definitions(-std=c++11)
set(CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS, "${CXX_FLAGS}")
set(sources src/main.cpp)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
include_directories("C:/Program Files/OpenSSL-Win64/include")
include_directories("C:/Program Files/OpenSSL-Win64/lib")
include_directories("C:/Program Files/xmrig-deps-4.1/gcc/x64/include")
include_directories("C:/Program Files/xmrig-deps-4.1/gcc/x64/lib")
include_directories("C:/Program Files/zlib-1.2.11")
set(CMAKE_CXX_FLAGS, "${CXX_FLAGS} -fpermissive")
add_definitions(-D_USE_MATH_DEFINES)
add_definitions(-fpermissive)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)
include_directories(/usr/local/opt/openssl/include)
link_directories(/usr/local/lib)
link_directories(/usr/local/opt/openssl/lib)
link_directories(/usr/local/Cellar/libuv/1.11.0/lib)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_executable(path_planning ${sources})
target_link_libraries(path_planning zlib-1.2.11 OpenSSL-Win64 xmrig-deps-4.1 uWebSockets)
#target_link_libraries(path_planning z ssl uv uWS)
Thank you very much!
EDIT:
I have found that CLion actually allows you to use the Linux Subsystem to build directly in your Windows environment, all that you have to is set it up as a remote environment:
https://www.jetbrains.com/help/clion/how-to-use-wsl-development-environment-in-clion.html
This allowed me to build and run directly from my windows setup!
I am planning to use Box2D in my C++ project. I have downloaded the latest version (v2.3.0.7 when asking this question) of Box2D and built it successfully. I can run the Testbed without any errors.
Now, I am trying to build the HelloWorld.cpp example, which resides in HelloWorld folder in Box2D source files but I can't compile this example.
Below is my command for compiling:
g++ -g -Wall -L/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D/Build/Box2D -lBox2D -I/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D HelloWorld.cpp -o Hello
And this is the output I get:
/tmp/cc2U314E.o: In function `main':
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:37: undefined reference to `b2World::b2World(b2Vec2 const&)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:46: undefined reference to `b2World::CreateBody(b2BodyDef const*)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:52: undefined reference to `b2PolygonShape::SetAsBox(float, float)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:55: undefined reference to `b2Body::CreateFixture(b2Shape const*, float)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:61: undefined reference to `b2World::CreateBody(b2BodyDef const*)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:65: undefined reference to `b2PolygonShape::SetAsBox(float, float)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:78: undefined reference to `b2Body::CreateFixture(b2FixtureDef const*)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:92: undefined reference to `b2World::Step(float, int, int)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:104: undefined reference to `b2World::~b2World()'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:104: undefined reference to `b2World::~b2World()'
/tmp/cc2U314E.o: In function `b2PolygonShape':
/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D/Box2D/Collision/Shapes/b2PolygonShape.h:87: undefined reference to `vtable for b2PolygonShape'
/tmp/cc2U314E.o: In function `~b2PolygonShape':
/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D/Box2D/Collision/Shapes/b2PolygonShape.h:28: undefined reference to `vtable for b2PolygonShape'
collect2: ld returned 1 exit status
I'm using
-L flag for searching for libBox2D.a
-l flag for linking Box2D
-I flag for pointing to the Box2D headers directory
What am I missing? Is there any specific library or command argument I am supposed to add?
Put the -lBox2D behind the HelloWorld.cpp
If you have built your project properly the HelloWorld example will be automatically built for you. There's a CMakeLists.txt file in the example folder just run cmake CMakeLists.txt in the folder and then run make. Prior to this you must have built and installed Box2D library. Here is what I did:
I entered the Build directory within the Box2D and typed the following command:
cmake -DBOX2D_INSTALL=ON -DBOX2D_BUILD_SHARED=ON -DCMAKE_INSTALL_PREFIX=/opt/Box2D ..
Then I went one level up to Box2D directory and ran make then sudo make install.
Then I entered the HelloWorld directory and it was automatically built. I didn't have to build it manually. Also this is the output from make that showed the example was built:
Linking CXX static library libBox2D.a
[ 42%] Built target Box2D
[ 43%] Building CXX object HelloWorld/CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o