Can't link with libLLVMSupport.a - linker

I'm trying to compile reduced clang "driver.cpp" - added printf for arguments - and i'm getting linking with libLLVMSupport.a error - no StringSaver class found.
# lib
echo "compiling cmd builder (x86_64) ..."
clang++ `../llvm_34_local_installed2/bin/llvm-config --cxxflags` -I ../llvm_34/tools/clang/include -I ../llvm_34_build_local2/tools/clang/include -c ./lib_cmd_builder.cpp -o ./lib_cmd_builder_x86_64.o
echo "linking cmd builder (x86_64) ..."
CMD="clang++ `../llvm_34_local_installed2/bin/llvm-config --ldflags` ./lib_cmd_builder_x86_64.o -o exe_cmd_builder_x86_64 `../llvm_34_local_installed2/bin/llvm-config --libs` -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangAnalysis -lclangApplyReplacements -lclangBasic -lclangCodeGen -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex -lclangParse -lclangQuery -lclangRewriteCore -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTidy -lclangTidyGoogleModule -lclangTidyLLVMModule"
echo "[${CMD}]"
${CMD}
Error message:
Undefined symbols for architecture x86_64:
"typeinfo for llvm::cl::StringSaver", referenced from:
typeinfo for (anonymous namespace)::StringSetSaver in lib_cmd_builder_x86_64.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Checking libLLVM is found and contains CommandLine object data:
(found on -L path):
find ../llvm_34_local_installed2/lib/ -name "*upport*"
../llvm_34_local_installed2/lib//libLLVMSupport.a
(contains CommandLine.cpp object data):
ar -t ../llvm_34_local_installed2/lib//libLLVMSupport.a | grep CommandLine
CommandLine.cpp.o
The class StringSaver is declared in CommandLine.cpp:
/Users/asmirnov/Documents/dev/src/llvm_34/include/llvm/Support/CommandLine.h
class StringSaver {
virtual void anchor();
public:
virtual const char *SaveString(const char *Str) = 0;
virtual ~StringSaver() {}; // Pacify -Wnon-virtual-dtor.
};
StringSaver inheritor is declared and implemented in self file (lib_cmd_builder.cpp):
namespace {
class StringSetSaver : public llvm::cl::StringSaver {
public:
StringSetSaver(std::set<std::string> &Storage) : Storage(Storage) {}
const char *SaveString(const char *Str) LLVM_OVERRIDE {
return SaveStringInSet(Storage, Str);
}
private:
std::set<std::string> &Storage;
};
}
i've also checked llvm-config output and it seems to be ok (contain -L and -lLLVMSupport):
clang++ -L/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/lib -lcurses -lpthread -lz ./lib_cmd_builder_x86_64.o -o exe_cmd_builder_x86_64 -lLLVMInstrumentation -lLLVMIRReader -lLLVMAsmParser -lLLVMDebugInfo -lLLVMOption -lLLVMLTO -lLLVMLinker -lLLVMipo -lLLVMVectorize -lLLVMBitWriter -lLLVMBitReader -lLLVMTableGen -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMR600CodeGen -lLLVMR600Desc -lLLVMR600Info -lLLVMR600AsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMHexagonCodeGen -lLLVMHexagonAsmPrinter -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMMCDisassembler -lLLVMMCParser -lLLVMInterpreter -lLLVMMCJIT -lLLVMJIT -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangAnalysis -lclangApplyReplacements -lclangBasic -lclangCodeGen -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex -lclangParse -lclangQuery -lclangRewriteCore -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTidy -lclangTidyGoogleModule -lclangTidyLLVMModule
Also checked it's build for x86_64 (my host device):
lipo -info ../llvm_34_local_installed2/lib/libLLVMSupport.a
input file ../llvm_34_local_installed2/lib/libLLVMSupport.a is not a fat file
Non-fat file: ../llvm_34_local_installed2/lib/libLLVMSupport.a is architecture: x86_64

I had to use -fno-rtti while compiling library sources

Related

A C language ffmpeg project organized with CMakeLists, encounters errors in the Windows MinGW64 environment

Project Structure
ffmpeg-tutorial
include
libavcodec
libavdevice
libavfilter
libavformat
libavutil
libswresample
libswscale
lib
pkgconfig
libavcodec.a
libavdevice.a
libavfilter.a
libformat.a
libavutil.a
libswresample.a
libswscale.a
CMakeLists.txt
main.c
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(ffmpeg_tutorial)
set(CMAKE_C_STANDARD 11)
include_directories(include)
link_directories(lib)
add_executable(ffmpeg_tutorial main.cpp)
target_link_libraries(ffmpeg_tutorial
avformat
avcodec
avutil
swscale
swresample
z
bz2
iconv
ws2_32
schannel
kernel32
advapi32
kernel32
user32
gdi32
winspool
shell32
ole32
oleaut32
uuid
comdlg32
advapi32
)
main.c
#include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswresample/swresample.h"
int main() {
std::cout << "Hello, World!" << std::endl;
std::cout << av_version_info() << std::endl;
printf("ffmpeg version is %s\n", av_version_info());
// Open input file
AVFormatContext *inputContext = nullptr;
if (avformat_open_input(&inputContext, "input.mp3", nullptr, nullptr) != 0) {
printf("Couldn't open input file\n");
return -1;
}
// Read input stream
if (avformat_find_stream_info(inputContext, nullptr) < 0) {
printf("Couldn't find stream information\n");
return -1;
}
// Get audio stream index
int audioStream = -1;
for (int i = 0; i < inputContext->nb_streams; i++) {
if (inputContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
audioStream = i;
break;
}
}
if (audioStream == -1) {
printf("Couldn't find audio stream\n");
return -1;
}
}
IDE
clion
ERRORS
[ 50%] Building CXX object CMakeFiles/ffmpeg_tutorial.dir/main.cpp.obj
[100%] Linking CXX executable ffmpeg_tutorial.exe
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavformat.a(tls_schannel.o): in function `tls_write':
D:\Msys64\usr\src\ffmpeg/libavformat/tls_schannel.c:563: undefined reference to `EncryptMessage'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavformat.a(tls_schannel.o): in function `tls_read':
D:\Msys64\usr\src\ffmpeg/libavformat/tls_schannel.c:441: undefined reference to `DecryptMessage'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavcodec.a(mfenc.o):mfenc.c:(.rdata$.refptr.IID_ICodecAPI[.refptr.IID_ICodecAPI]+0x0): undefined reference to `IID_ICodecAPI'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavcodec.a(tiff.o): in function `tiff_uncompress_lzma':
D:\Msys64\usr\src\ffmpeg/libavcodec/tiff.c:577: undefined reference to `lzma_stream_decoder'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavcodec/tiff.c:582: undefined reference to `lzma_code'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavcodec/tiff.c:583: undefined reference to `lzma_end'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavutil.a(random_seed.o): in function `av_get_random_seed':
D:\Msys64\usr\src\ffmpeg/libavutil/random_seed.c:127: undefined reference to `BCryptOpenAlgorithmProvider'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavutil/random_seed.c:130: undefined reference to `BCryptGenRandom'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavutil/random_seed.c:131: undefined reference to `BCryptCloseAlgorithmProvider'
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\ffmpeg_tutorial.dir\build.make:95: ffmpeg_tutorial.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/ffmpeg_tutorial.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/ffmpeg_tutorial.dir/rule] Error 2
mingw32-make: *** [Makefile:123: ffmpeg_tutorial] Error 2
What is the way I compile ffmpeg
downlaod msys2
install mingw64
pacman -S mingw-w64-x86_64-toolchain
install make,diffutils,nasm,yasm,pkg-config
pacman -S base-devl yasm nasm pkg-config
download ffmpeg 5.1
compile
cd ffmpeg
./configure --disable-shared --enable-static --arch=x86_64 --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32- --pkg-config-flags=--static --prefix=../ffmpeg-build
make -j $(nproc)
make install
Project Repoistory
https://github.com/joinwen/learn_ffmpeg.git
Expectation
How to solve errors
In CMakeLists target_link_libraries's parameters is too much, Can I make it short
some advices on the project

Undefined References in CBLAS when testing GSL with CMake

I've just installed GSL on my Deepin OS(Linux), and for testing my installation I'm trying to compile a testing file. When compiling with gcc, it works properly, but when using CMake, some Undefined Reference error occurs.
I tried compiling the file main.c with gcc :
gcc main.c -o demo -lm -lgsl -lgslcblas
./demo
and it works properly. But when I tried CMake :
cmake .
make
with a CMakeLists.txt file that looks like :
# CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(demo)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(SOURCE_FILES main.c)
add_executable(demo ${SOURCE_FILES})
find_package(GSL REQUIRED)
target_link_libraries(demo GSL::gsl GSL::gslcblas)
such error occurs :
(The output is in Chinese, because of the system language. For example :
/usr/local/lib/libcblas.a(cblas_srotg.o):在函数‘cblas_srotg’中:
cblas_srotg.c:(.text+0x1):对‘srotg_’未定义的引用
means :
/usr/local/lib/libcblas.a(cblas_srotg.o):In function ‘cblas_srotg’ :
cblas_srotg.c:(.text+0x1):Undefined reference to ‘srotg_’.
)
[ 50%] Linking C executable demo
/usr/local/lib/libcblas.a(cblas_srotg.o):在函数‘cblas_srotg’中:
cblas_srotg.c:(.text+0x1):对‘srotg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_srotmg.o):在函数‘cblas_srotmg’中:
cblas_srotmg.c:(.text+0x13):对‘srotmg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_srot.o):在函数‘cblas_srot’中:
cblas_srot.c:(.text+0x3c):对‘srot_’未定义的引用
/usr/local/lib/libcblas.a(cblas_srotm.o):在函数‘cblas_srotm’中:
cblas_srotm.c:(.text+0x21):对‘srotm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sswap.o):在函数‘cblas_sswap’中:
cblas_sswap.c:(.text+0x21):对‘sswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sscal.o):在函数‘cblas_sscal’中:
cblas_sscal.c:(.text+0x28):对‘sscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_scopy.o):在函数‘cblas_scopy’中:
cblas_scopy.c:(.text+0x21):对‘scopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_saxpy.o):在函数‘cblas_saxpy’中:
cblas_saxpy.c:(.text+0x35):对‘saxpy_’未定义的引用
/usr/local/lib/libcblas.a(sdotsub.o):在函数‘sdotsub_’中:
sdotsub.f:(.text+0x7):对‘sdot_’未定义的引用
/usr/local/lib/libcblas.a(sdsdotsub.o):在函数‘sdsdotsub_’中:
sdsdotsub.f:(.text+0x7):对‘sdsdot_’未定义的引用
/usr/local/lib/libcblas.a(snrm2sub.o):在函数‘snrm2sub_’中:
snrm2sub.f:(.text+0x7):对‘snrm2_’未定义的引用
/usr/local/lib/libcblas.a(sasumsub.o):在函数‘sasumsub_’中:
sasumsub.f:(.text+0x7):对‘sasum_’未定义的引用
/usr/local/lib/libcblas.a(isamaxsub.o):在函数‘isamaxsub_’中:
isamaxsub.f:(.text+0x7):对‘isamax_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drotg.o):在函数‘cblas_drotg’中:
cblas_drotg.c:(.text+0x1):对‘drotg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drotmg.o):在函数‘cblas_drotmg’中:
cblas_drotmg.c:(.text+0x13):对‘drotmg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drot.o):在函数‘cblas_drot’中:
cblas_drot.c:(.text+0x3b):对‘drot_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drotm.o):在函数‘cblas_drotm’中:
cblas_drotm.c:(.text+0x21):对‘drotm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dswap.o):在函数‘cblas_dswap’中:
cblas_dswap.c:(.text+0x21):对‘dswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dscal.o):在函数‘cblas_dscal’中:
cblas_dscal.c:(.text+0x25):对‘dscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dcopy.o):在函数‘cblas_dcopy’中:
cblas_dcopy.c:(.text+0x21):对‘dcopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_daxpy.o):在函数‘cblas_daxpy’中:
cblas_daxpy.c:(.text+0x38):对‘daxpy_’未定义的引用
/usr/local/lib/libcblas.a(ddotsub.o):在函数‘ddotsub_’中:
ddotsub.f:(.text+0x7):对‘ddot_’未定义的引用
/usr/local/lib/libcblas.a(dsdotsub.o):在函数‘dsdotsub_’中:
dsdotsub.f:(.text+0x7):对‘dsdot_’未定义的引用
/usr/local/lib/libcblas.a(dnrm2sub.o):在函数‘dnrm2sub_’中:
dnrm2sub.f:(.text+0x7):对‘dnrm2_’未定义的引用
/usr/local/lib/libcblas.a(dasumsub.o):在函数‘dasumsub_’中:
dasumsub.f:(.text+0x7):对‘dasum_’未定义的引用
/usr/local/lib/libcblas.a(idamaxsub.o):在函数‘idamaxsub_’中:
idamaxsub.f:(.text+0x7):对‘idamax_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cswap.o):在函数‘cblas_cswap’中:
cblas_cswap.c:(.text+0x21):对‘cswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cscal.o):在函数‘cblas_cscal’中:
cblas_cscal.c:(.text+0x17):对‘cscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csscal.o):在函数‘cblas_csscal’中:
cblas_csscal.c:(.text+0x28):对‘csscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ccopy.o):在函数‘cblas_ccopy’中:
cblas_ccopy.c:(.text+0x21):对‘ccopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_caxpy.o):在函数‘cblas_caxpy’中:
cblas_caxpy.c:(.text+0x21):对‘caxpy_’未定义的引用
/usr/local/lib/libcblas.a(cdotcsub.o):在函数‘cdotcsub_’中:
cdotcsub.f:(.text+0xb):对‘cdotc_’未定义的引用
/usr/local/lib/libcblas.a(cdotusub.o):在函数‘cdotusub_’中:
cdotusub.f:(.text+0xb):对‘cdotu_’未定义的引用
/usr/local/lib/libcblas.a(icamaxsub.o):在函数‘icamaxsub_’中:
icamaxsub.f:(.text+0x7):对‘icamax_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zswap.o):在函数‘cblas_zswap’中:
cblas_zswap.c:(.text+0x21):对‘zswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zscal.o):在函数‘cblas_zscal’中:
cblas_zscal.c:(.text+0x17):对‘zscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zdscal.o):在函数‘cblas_zdscal’中:
cblas_zdscal.c:(.text+0x25):对‘zdscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zcopy.o):在函数‘cblas_zcopy’中:
cblas_zcopy.c:(.text+0x21):对‘zcopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zaxpy.o):在函数‘cblas_zaxpy’中:
cblas_zaxpy.c:(.text+0x21):对‘zaxpy_’未定义的引用
/usr/local/lib/libcblas.a(zdotcsub.o):在函数‘zdotcsub_’中:
zdotcsub.f:(.text+0x7):对‘zdotc_’未定义的引用
/usr/local/lib/libcblas.a(zdotusub.o):在函数‘zdotusub_’中:
zdotusub.f:(.text+0x7):对‘zdotu_’未定义的引用
/usr/local/lib/libcblas.a(dzasumsub.o):在函数‘dzasumsub_’中:
dzasumsub.f:(.text+0x7):对‘dzasum_’未定义的引用
/usr/local/lib/libcblas.a(dznrm2sub.o):在函数‘dznrm2sub_’中:
dznrm2sub.f:(.text+0x7):对‘dznrm2_’未定义的引用
/usr/local/lib/libcblas.a(izamaxsub.o):在函数‘izamaxsub_’中:
izamaxsub.f:(.text+0x7):对‘izamax_’未定义的引用
/usr/local/lib/libcblas.a(scasumsub.o):在函数‘scasumsub_’中:
scasumsub.f:(.text+0x7):对‘scasum_’未定义的引用
/usr/local/lib/libcblas.a(scnrm2sub.o):在函数‘scnrm2sub_’中:
scnrm2sub.f:(.text+0x7):对‘scnrm2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sgemv.o):在函数‘cblas_sgemv’中:
cblas_sgemv.c:(.text+0x124):对‘sgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sger.o):在函数‘cblas_sger’中:
cblas_sger.c:(.text+0xab):对‘sger_’未定义的引用
cblas_sger.c:(.text+0xe3):对‘sger_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssymv.o):在函数‘cblas_ssymv’中:
cblas_ssymv.c:(.text+0xb4):对‘ssymv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyr.o):在函数‘cblas_ssyr’中:
cblas_ssyr.c:(.text+0xa8):对‘ssyr_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyr2.o):在函数‘cblas_ssyr2’中:
cblas_ssyr2.c:(.text+0xb2):对‘ssyr2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strmv.o):在函数‘cblas_strmv’中:
cblas_strmv.c:(.text+0x141):对‘strmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strsv.o):在函数‘cblas_strsv’中:
cblas_strsv.c:(.text+0x141):对‘strsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dgemv.o):在函数‘cblas_dgemv’中:
cblas_dgemv.c:(.text+0x120):对‘dgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dger.o):在函数‘cblas_dger’中:
cblas_dger.c:(.text+0xb3):对‘dger_’未定义的引用
cblas_dger.c:(.text+0xeb):对‘dger_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsymv.o):在函数‘cblas_dsymv’中:
cblas_dsymv.c:(.text+0xb4):对‘dsymv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyr.o):在函数‘cblas_dsyr’中:
cblas_dsyr.c:(.text+0xa6):对‘dsyr_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyr2.o):在函数‘cblas_dsyr2’中:
cblas_dsyr2.c:(.text+0xb0):对‘dsyr2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrmv.o):在函数‘cblas_dtrmv’中:
cblas_dtrmv.c:(.text+0x141):对‘dtrmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrsv.o):在函数‘cblas_dtrsv’中:
cblas_dtrsv.c:(.text+0x141):对‘dtrsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgemv.o):在函数‘cblas_cgemv’中:
cblas_cgemv.c:(.text+0x205):对‘cgemv_’未定义的引用
cblas_cgemv.c:(.text+0x290):对‘cgemv_’未定义的引用
cblas_cgemv.c:(.text+0x36d):对‘cgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_chemv.o):在函数‘cblas_chemv’中:
cblas_chemv.c:(.text+0x219):对‘chemv_’未定义的引用
cblas_chemv.c:(.text+0x2f0):对‘chemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrmv.o):在函数‘cblas_ctrmv’中:
cblas_ctrmv.c:(.text+0x146):对‘ctrmv_’未定义的引用
cblas_ctrmv.c:(.text+0x200):对‘ctrmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrsv.o):在函数‘cblas_ctrsv’中:
cblas_ctrsv.c:(.text+0x154):对‘ctrsv_’未定义的引用
cblas_ctrsv.c:(.text+0x210):对‘ctrsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgeru.o):在函数‘cblas_cgeru’中:
cblas_cgeru.c:(.text+0xa6):对‘cgeru_’未定义的引用
cblas_cgeru.c:(.text+0xd9):对‘cgeru_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgerc.o):在函数‘cblas_cgerc’中:
cblas_cgerc.c:(.text+0x13d):对‘cgeru_’未定义的引用
cblas_cgerc.c:(.text+0x18f):对‘cgeru_’未定义的引用
cblas_cgerc.c:(.text+0x1ef):对‘cgerc_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cher.o):在函数‘cblas_cher’中:
cblas_cher.c:(.text+0x10a):对‘cher_’未定义的引用
cblas_cher.c:(.text+0x1f7):对‘cher_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cher2.o):在函数‘cblas_cher2’中:
cblas_cher2.c:(.text+0x17a):对‘cher2_’未定义的引用
cblas_cher2.c:(.text+0x281):对‘cher2_’未定义的引用
cblas_cher2.c:(.text+0x2bc):对‘cher2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgemv.o):在函数‘cblas_zgemv’中:
cblas_zgemv.c:(.text+0x20f):对‘zgemv_’未定义的引用
cblas_zgemv.c:(.text+0x298):对‘zgemv_’未定义的引用
cblas_zgemv.c:(.text+0x37c):对‘zgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zhemv.o):在函数‘cblas_zhemv’中:
cblas_zhemv.c:(.text+0x219):对‘zhemv_’未定义的引用
cblas_zhemv.c:(.text+0x2f0):对‘zhemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrmv.o):在函数‘cblas_ztrmv’中:
cblas_ztrmv.c:(.text+0x155):对‘ztrmv_’未定义的引用
cblas_ztrmv.c:(.text+0x210):对‘ztrmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrsv.o):在函数‘cblas_ztrsv’中:
cblas_ztrsv.c:(.text+0x155):对‘ztrsv_’未定义的引用
cblas_ztrsv.c:(.text+0x210):对‘ztrsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgeru.o):在函数‘cblas_zgeru’中:
cblas_zgeru.c:(.text+0xa6):对‘zgeru_’未定义的引用
cblas_zgeru.c:(.text+0xd9):对‘zgeru_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgerc.o):在函数‘cblas_zgerc’中:
cblas_zgerc.c:(.text+0x13e):对‘zgeru_’未定义的引用
cblas_zgerc.c:(.text+0x18f):对‘zgeru_’未定义的引用
cblas_zgerc.c:(.text+0x1ef):对‘zgerc_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zher.o):在函数‘cblas_zher’中:
cblas_zher.c:(.text+0x14b):对‘zher_’未定义的引用
cblas_zher.c:(.text+0x1a5):对‘zher_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zher2.o):在函数‘cblas_zher2’中:
cblas_zher2.c:(.text+0x17b):对‘zher2_’未定义的引用
cblas_zher2.c:(.text+0x281):对‘zher2_’未定义的引用
cblas_zher2.c:(.text+0x2bc):对‘zher2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sgemm.o):在函数‘cblas_sgemm’中:
cblas_sgemm.c:(.text+0x10f):对‘sgemm_’未定义的引用
cblas_sgemm.c:(.text+0x1a7):对‘sgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssymm.o):在函数‘cblas_ssymm’中:
cblas_ssymm.c:(.text+0xe8):对‘ssymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyrk.o):在函数‘cblas_ssyrk’中:
cblas_ssyrk.c:(.text+0xd7):对‘ssyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyr2k.o):在函数‘cblas_ssyr2k’中:
cblas_ssyr2k.c:(.text+0xe5):对‘ssyr2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strmm.o):在函数‘cblas_strmm’中:
cblas_strmm.c:(.text+0x12a):对‘strmm_’未定义的引用
cblas_strmm.c:(.text+0x1f0):对‘strmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strsm.o):在函数‘cblas_strsm’中:
cblas_strsm.c:(.text+0x12a):对‘strsm_’未定义的引用
cblas_strsm.c:(.text+0x1f0):对‘strsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dgemm.o):在函数‘cblas_dgemm’中:
cblas_dgemm.c:(.text+0x10f):对‘dgemm_’未定义的引用
cblas_dgemm.c:(.text+0x1a7):对‘dgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsymm.o):在函数‘cblas_dsymm’中:
cblas_dsymm.c:(.text+0xe8):对‘dsymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyrk.o):在函数‘cblas_dsyrk’中:
cblas_dsyrk.c:(.text+0xd7):对‘dsyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyr2k.o):在函数‘cblas_dsyr2k’中:
cblas_dsyr2k.c:(.text+0xe5):对‘dsyr2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrmm.o):在函数‘cblas_dtrmm’中:
cblas_dtrmm.c:(.text+0x122):对‘dtrmm_’未定义的引用
cblas_dtrmm.c:(.text+0x1e0):对‘dtrmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrsm.o):在函数‘cblas_dtrsm’中:
cblas_dtrsm.c:(.text+0x122):对‘dtrsm_’未定义的引用
cblas_dtrsm.c:(.text+0x1e0):对‘dtrsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgemm.o):在函数‘cblas_cgemm’中:
cblas_cgemm.c:(.text+0x105):对‘cgemm_’未定义的引用
cblas_cgemm.c:(.text+0x19d):对‘cgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csymm.o):在函数‘cblas_csymm’中:
cblas_csymm.c:(.text+0xe6):对‘csymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_chemm.o):在函数‘cblas_chemm’中:
cblas_chemm.c:(.text+0xe6):对‘chemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cherk.o):在函数‘cblas_cherk’中:
cblas_cherk.c:(.text+0xd7):对‘cherk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cher2k.o):在函数‘cblas_cher2k’中:
cblas_cher2k.c:(.text+0x108):对‘cher2k_’未定义的引用
cblas_cher2k.c:(.text+0x185):对‘cher2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrmm.o):在函数‘cblas_ctrmm’中:
cblas_ctrmm.c:(.text+0x118):对‘ctrmm_’未定义的引用
cblas_ctrmm.c:(.text+0x1d6):对‘ctrmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrsm.o):在函数‘cblas_ctrsm’中:
cblas_ctrsm.c:(.text+0x118):对‘ctrsm_’未定义的引用
cblas_ctrsm.c:(.text+0x1d6):对‘ctrsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csyrk.o):在函数‘cblas_csyrk’中:
cblas_csyrk.c:(.text+0xd5):对‘csyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csyr2k.o):在函数‘cblas_csyr2k’中:
cblas_csyr2k.c:(.text+0xe3):对‘csyr2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgemm.o):在函数‘cblas_zgemm’中:
cblas_zgemm.c:(.text+0x105):对‘zgemm_’未定义的引用
cblas_zgemm.c:(.text+0x19d):对‘zgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zsymm.o):在函数‘cblas_zsymm’中:
cblas_zsymm.c:(.text+0xe6):对‘zsymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zhemm.o):在函数‘cblas_zhemm’中:
cblas_zhemm.c:(.text+0xe6):对‘zhemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zherk.o):在函数‘cblas_zherk’中:
cblas_zherk.c:(.text+0xd7):对‘zherk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zher2k.o):在函数‘cblas_zher2k’中:
cblas_zher2k.c:(.text+0x109):对‘zher2k_’未定义的引用
cblas_zher2k.c:(.text+0x18d):对‘zher2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrmm.o):在函数‘cblas_ztrmm’中:
cblas_ztrmm.c:(.text+0x118):对‘ztrmm_’未定义的引用
cblas_ztrmm.c:(.text+0x1d6):对‘ztrmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrsm.o):在函数‘cblas_ztrsm’中:
cblas_ztrsm.c:(.text+0x118):对‘ztrsm_’未定义的引用
cblas_ztrsm.c:(.text+0x1d6):对‘ztrsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zsyrk.o):在函数‘cblas_zsyrk’中:
cblas_zsyrk.c:(.text+0xd5):对‘zsyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zsyr2k.o):在函数‘cblas_zsyr2k’中:
cblas_zsyr2k.c:(.text+0xe3):对‘zsyr2k_’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/demo.dir/build.make:96: recipe for target 'demo' failed
make[2]: *** [demo] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/demo.dir/all' failed
make[1]: *** [CMakeFiles/demo.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
To determine how is the problem brought up, I also tried reproducing the error message with gcc. When compiling with this command :
$ gcc main.c -o demo -lm -lgsl -lcblas -lblas
it works well. When trying :
$ gcc main.c -o demo -lm -lgsl -lcblas # Ignoring BLAS library.
The error message is reproduced. So I guess the problem occurs when linking the BLAS library.
Here is the file main.c
// main.c
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main(void) {
double x = 5.0;
double y;
y = gsl_sf_bessel_J0(x);
printf("J0(%.4lf) = %.4le\n", x, y);
return 0;
}
The expected outcome would be :
J0(5.0000) = -1.7760e-01
Add the following to your CMakeList.txt
find_package(BLAS REQUIRED)

Why is this not a duplicate symbol error?

I have a iOS framework that contains .c, .mm source files.
For convenience let's call these two files A.c and B.mm.
In both files, I defined a function with the same function protocol like the following.
// A.c
uint32_t get_file(const char *path)
{
...
}
// B.mm
uint32_t get_file(const char *path)
{
...
}
As far as I know, I thought this would throw an error at compile time because there's duplicate symbol, but it successfully compiles the framework without any error. What am I missing here?
Note:
This will be a duplicate symbol linker error if it was .c and .m because Objective-C doesn't undergo name mangling.
Objective-C++ files (.mm) are C++ files, so they undergo name mangling. If you run nm on the output, you'll see something along the lines of:
$ nm a.out | grep get_file
0000000100000fa0 T __Z8get_filePKc
0000000100000f70 T _get_file
If you applied extern "C" in the C++ version to remove name mangling, you'd see the collision you're expecting:
// B.mm
extern "C" uint32_t get_file(const char *path)
{
return 0;
}
$ clang A.c B.mm
duplicate symbol _get_file in:
/var/folders/j3/32xftcp56c12hqz7y8rl4f600000gn/T/A-d00e10.o
/var/folders/j3/32xftcp56c12hqz7y8rl4f600000gn/T/B-d853af.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Compile gcrypt for Vala

I'm try to compile a code write in Vala using a .vapi of libgcrypt.
I installed the library in the system and i run a test in c. The code write in C compiles without errors:
I typed the following command to compile the C code:
gcc -o main main.c -l gcrypt
The code runs perfectly.
But, the following code write in Vala don't compile using the command:
valac --pkg gcrypt --Xcc=-lgcrypt main.vala
The main.vala is
using GCrypt;
public static int main(string[] args)
{
Hash h;
Hash.open(out h, Hash.Algorithm.MD5, Hash.Flag.SECURE);
return 0;
}
I don't know what i doing wrong.
EDITED:
Sorry for not post the error, but there is:
Loaded package /usr/share/vala-0.30/vapi/glib-2.0.vapi'
Loaded package /usr/share/vala-0.30/vapi/gobject-2.0.vapi'
Loaded package /usr/share/vala-0.30/vapi/gcrypt.vapi'
cc -o '/home/kyul/Documents/Codes/Vala/test_gcrypt/main' '/home/kyul/Documents/Codes/Vala/test_gcrypt/main.vala.c' -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lgobject-2.0 -lglib-2.0 '-lgcrypt'
/home/kyul/Documents/Codes/Vala/test_gcrypt/main.vala.c: In function ‘_vala_main’:
/home/kyul/Documents/Codes/Vala/test_gcrypt/main.vala.c:22:38: error: ‘GCRY_MD_FLAGSECURE’ undeclared (first use in this function)
gcry_md_open (&_tmp0_, GCRY_MD_MD5, GCRY_MD_FLAGSECURE);
^
/home/kyul/Documents/Codes/Vala/test_gcrypt/main.vala.c:22:38: note: each undeclared identifier is reported only once for each function it appears in
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
Most likely You are missing the .vapi file.
$ wget https://raw.githubusercontent.com/nemequ/vala-extra-vapis/master/gcrypt.vapi
$ patch < gcrypt.patch
$ valac --vapidir=. --pkg gcrypt --Xcc=-lgcrypt main.vala
$ ./main
$ echo $?
0
I've never used gcrypt api from vala before and had to patch gcrypt.vapi for Your example to work, but the patch is trivial:
--- gcrypt.vapi
+++ gcrypt.vapi
## -619,7 +619,7 ##
public Error get_oid (uchar[] buffer);
}
- [CCode (cname = "enum gcry_md_flags", cprefix = "GCRY_MD_FLAG")]
+ [CCode (cname = "enum gcry_md_flags", cprefix = "GCRY_MD_FLAG_")]
public enum Flag {
SECURE,
HMAC
Update: concerning Your cipher errors, obviously the Cipher class is missing free_function mapping:
--- a/gcrypt.vapi 2016-02-22 21:40:34.458977385 +0200
+++ b/gcrypt.vapi 2016-02-22 21:39:59.662976449 +0200
## -560,7 +560,7 ##
CBC_MAC /* Enable CBC message auth. code (MAC). */
}
[Compact]
- [CCode (cname = "gcry_cipher_hd_t", lower_case_cprefix = "gcry_cipher_")]
+ [CCode (cname = "struct gcry_cipher_handle", lower_case_cprefix = "gcry_cipher_", free_function = "gcry_cipher_close")]
public class Cipher {
public static Error open (out Cipher cipher, Algorithm algo, Mode mode, Flag flags);
public void close ();

ARM equivalent of "--exclude-libs ALL"

Is there an ld(1) option that provides the equivalent of --exclude-libs ALL on ARM platforms?
I'm trying to reduce the size of a shared object on Android, but --exclude-libs ALL is only available on x86.
EDIT: here's the reason I ask. Sorry about this extra detail. I was trying to keep the question short. My shared object does not export any Crypto++ symbols, yet 88 are showing up with and without --exclude-libs ALL.
Here are the envars of interest:
$ echo $CXX
arm-linux-androideabi-g++
$ echo $ANDROID_STL_INC
/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/
$ echo $ANDROID_SYSROOT
/opt/android-ndk-r9/platforms/android-9/arch-arm
First, build my shared object without --exclude-libs ALL:
$ $CXX -fPIC -Os -I/usr/local/cryptopp-android-9/include -I$ANDROID_STL_INC
--sysroot=$ANDROID_SYSROOT com_deltoid_androidprng_PRNG.cpp
-o libprng.so -shared
And then count the number of Crypto++ exports:
$ arm-linux-androideabi-nm --defined-only libprng.so | grep -i cryptopp | wc -l
88
Second, same experiment with --exclude-libs ALL:
$ $CXX -fPIC -Os -I/usr/local/cryptopp-android-9/include -I$ANDROID_STL_INC
--sysroot=$ANDROID_SYSROOT com_deltoid_androidprng_PRNG.cpp
-o libprng.so -shared -Wl,--exclude-libs,ALL
And then count the number of Crypto++ exports:
$ arm-linux-androideabi-nm --defined-only libprng.so | grep -i cryptopp | wc -l
88
In both cases, 88 Crypto++ symbols are being exported. The source file is below, an it does not export any Crypto++ symbols.
#include <string.h>
#include <jni.h>
#include <cryptopp/osrng.h>
using CryptoPP::AutoSeededRandomPool;
#include "com_deltoid_androidprng_PRNG.h"
static AutoSeededRandomPool& GetPRNG()
{
static AutoSeededRandomPool prng;
return prng;
}
static int IncorporateSensors()
{
return 0;
}
/*
* Class: com_deltoid_androidprng_PRNG
* Method: CryptoPP_Reseed
* Signature: ([B)I
*/
jint JNICALL Java_com_deltoid_androidprng_PRNG_CryptoPP_1Reseed
(JNIEnv* env, jclass, jbyteArray seed)
{
int ret, consumed = 0;
try
{
AutoSeededRandomPool& prng = GetPRNG();
if(env)
{
jbyte* bytes = env->GetByteArrayElements(seed, 0);
jint length = env->GetArrayLength(seed);
if(bytes)
{
if(length >= 0)
{
prng.IncorporateEntropy((const byte*)bytes, (size_t)length);
consumed += length;
}
env->ReleaseByteArrayElements(seed, bytes, JNI_ABORT);
}
}
}
catch(const CryptoPP::Exception& ex)
{
}
return consumed;
}
/*
* Class: com_deltoid_androidprng_PRNG
* Method: CryptoPP_GetBytes
* Signature: ([B)I
*/
JNIEXPORT jint JNICALL Java_com_deltoid_androidprng_PRNG_CryptoPP_1GetBytes
(JNIEnv *, jclass, jbyteArray)
{
}
I'm pretty sure --exclude-libs is supported by Android / ARM version of ld, since they use it themselves as well.
Did you try something like below in your Android.mk file?
LOCAL_LDFLAGS += -Wl,--exclude-libs,ALL

Resources