I want to build Clang compiling for STM32 (arm-none-eabi) under x64 Windows 10, then setup VSCode to use this Clang to compile my stm32 firmwares to ARM binaries. I have read LLVM manuals, there is no clear information (or it just doesnt work) how to make an LLVM crosscompiler for ARM under Windows. I run cmake and ninja within Powershell after running the Native x64 devtools vcvarsall.bat, using following configuration for cmake:
cmake -GNinja -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_TARGET_ARCH=ARM -DLLVM_HOST_TRIPLE="x86_64-pc-windows" -DLLVM_DEFAULT_TARGET_TRIPLE="arm-none-eabi" -DCMAKE_CXX_STANDARD=17 -DLLVM_USE_CRT_DEBUG=MDd -DLLVM_USE_CRT_RELEASE=MD ..\llvm-project\llvm\
And after running "ninja clang" I got this (I think it cant find proper ucrt library build (x64 Release) should be located somewhere in Windows sdk folder, but if I attempt to pass it to cmake, it doesnt change anything):
-- Build files have been written to: C:/Users/iTXS/build_ninja
PS C:\Users\iTXS\build_ninja> ninja clang
[1/1992] Linking CXX executable bin\clang-tblgen.exe
FAILED: bin/clang-tblgen.exe
cmd.exe /C "cd . && C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Werror=date-time -Werror=unguarded-availability-new -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -Xlinker /subsystem:console -Wl,--gc-sections tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangASTNodesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangASTPropertiesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangAttrEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentCommandInfoEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLTagsEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangDataCollectorsEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangDiagnosticsEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangOpcodesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangOpenCLBuiltinEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangOptionDocEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangSACheckersEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangSyntaxEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangTypeNodesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/MveEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/NeonEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/RISCVVEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/SveEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/TableGen.cpp.obj -o bin\clang-tblgen.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:lib\clang-tblgen.lib -Xlinker /pdb:bin\clang-tblgen.pdb -Xlinker /version:0.0 lib/LLVMSupport.lib lib/LLVMTableGen.lib lib/clangSupport.lib lib/LLVMSupport.lib lib/LLVMDemangle.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: warning: ignoring unknown argument '--gc-sections'
lld-link: error: undefined symbol: __declspec(dllimport) _CrtDbgReport
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced 5209 more times
lld-link: error: undefined symbol: __declspec(dllimport) _invalid_parameter
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced 5025 more times
lld-link: error: undefined symbol: __declspec(dllimport) _CrtSetReportHook
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::DisableSystemDialogsOnCrash(void))
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::PrintStackTraceOnErrorSignal(class llvm::StringRef, bool))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
[2/1992] Linking CXX executable bin\llvm-tblgen.exe
FAILED: bin/llvm-tblgen.exe
cmd.exe /C "cd . && C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Werror=date-time -Werror=unguarded-availability-new -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -Xlinker /subsystem:console -Wl,--gc-sections utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmWriterEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmWriterInst.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/Attributes.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CallingConvEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeEmitterGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenDAGPatterns.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenHwModes.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenInstruction.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenMapTable.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenRegisters.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenSchedule.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenTarget.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherOpt.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcher.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAPacketizerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DirectiveEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DisassemblerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DXILEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/ExegesisEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/FastISelEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/GICombinerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/GlobalISelEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/InfoByHwMode.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/InstrInfoEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/InstrDocsEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/IntrinsicEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptParserEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptRSTEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/PredicateExpander.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/PseudoLoweringEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CompressInstEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/RegisterBankEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/RegisterInfoEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SDNodeProperties.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SearchableTableEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SubtargetEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SubtargetFeatureInfo.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/TableGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/Types.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/VarLenCodeEmitterGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86DisassemblerTables.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86EVEX2VEXTablesEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86FoldTablesEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86MnemonicTables.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86ModRMFilters.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86RecognizableInstr.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/WebAssemblyDisassemblerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CTagsEmitter.cpp.obj -o bin\llvm-tblgen.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:lib\llvm-tblgen.lib -Xlinker /pdb:bin\llvm-tblgen.pdb -Xlinker /version:0.0 lib/LLVMSupport.lib lib/LLVMTableGen.lib lib/LLVMTableGenGlobalISel.lib lib/LLVMTableGen.lib lib/LLVMSupport.lib lib/LLVMDemangle.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: warning: ignoring unknown argument '--gc-sections'
lld-link: error: undefined symbol: __declspec(dllimport) _CrtDbgReport
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced 13261 more times
lld-link: error: undefined symbol: __declspec(dllimport) _invalid_parameter
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced 13252 more times
lld-link: error: undefined symbol: __declspec(dllimport) _CrtSetReportHook
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::DisableSystemDialogsOnCrash(void))
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::PrintStackTraceOnErrorSignal(class llvm::StringRef, bool))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
After digging I probably found the issue:
https://developercommunity.visualstudio.com/t/incorrect-ucrt-path-in-vc-includepath-vs-2022/1678876
after fully uninstalling all Windows SDKs and Universal C Runtimes and then PC restart and reinstalling them I have successfully built "clang" target. Hope it helps others
PS. I just wondered how many there are enum default type (int) overflow warnings due to occupancy of last bit in enum value e.g. 0x80000001, and many warnings about '__int64' type. Why not use stdint and exact-typed enums?? I think thats weird.
Related
I'm trying to compile a large code with gcc(5.3), which was compiled with icpc before.(I have mkl libraries loaded) Compilation was successful but with the following warning:
warning: narrowing conversion of 'p_jShell->simint_shell::nprim' from 'int' to
'unsigned int' inside { } [-Wnarrowing]
{ p_iShell->nprim, p_jShell->nprim };
But I get run time errors 'undefined referece' to __intel_ssse3_rep_memcpy, _mm_free,_mm_malloc,__svml_pow4,_intel_fast_memset etc..
In function `simgms_oei(std::vector<std::vector<simint_shell, std::allocator<simint_shell> >, std::allocator<std::vector<simint_shell, std::allocator<simint_shell> > > >&, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >&, unsigned int, AtomData&)':
/home/..../simgms_oei.cpp:126: undefined reference to `oed__memory_ovl_batch_'
..
..
In function `simint_copy_shell':
shell.c:(.text+0x126): undefined reference to `__intel_ssse3_rep_memcpy'
.
shell.c:(.text+0x32fe): undefined reference to `_mm_free'
shell.c:(.text+0x335c): undefined reference to `_mm_malloc'
.
ostei_p_s_f_p.c:(.text+0x27f): undefined reference to `_intel_fast_memset'
.
..
..
I suspect this could be from a linking problem. I linked gcc lib directory but I'm not sure what libraries I need to have here. Any suggestions? Anyone see what I'm doing wrong here? Thanks!
gcc -mavx -g -O -O1 -std=c++11 -L/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/lib64 -libstdc -libsupc++ -libtsan -libubsan -libvtv -libquadmath -libgcc_s -libgcj -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -libmkl_mc -libmkl_sequential -libmkl_gf_ilp64 -libmkl_avx -libmkl_lapack95_lp64 -libmkl_intel_lp64 -libmkl_core -lmkl_gnu_thread -I/opt/intel/composer_xe_2013.5.192/mkl/include -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -I/***/simint/include -DDEBUG -DMKL_ILP64 -MMD -MP -MF"simgms_init.d" -MT"simgms_init.d" -c -o "simgms_init.o" "../simgms_init.cpp"
I tried found the library all the cpp files(simgms_oei.cpp etc..) were compiled into and tried the nm commands below:
>> nm libsimint.a |grep __intel_ssse3_rep_memcpy
U __intel_ssse3_rep_memcpy
>> nm libsimint.a |grep simint_copy_shell
0000000000000090 T simint_copy_shell
When you lookup U and T it meant the following:
simint_copy_shell function is mentioned in code but __intel_ssse3_rep_memcpy is not defined in some other libray our libsimint is compiled with
The conclusion is that the library is compiled with icpc and I had to recompile it separately with gcc before linking it in the above step.
Adding Wl, command to the linker script like this:
--Wl,--start-group -L/opt/share... -lsomelib -lsomeotherlib -L/xxx/...-lsomelib -Wl,--end-group
Got rid of the other errors I had due to linking order.
Getting this error during wxWidgets compilation for FileZilla on Windows10/MSYS2/Cygwin.
$ ./configure --prefix="$HOME/prefix" --enable-static --disable-shared
--build=x86_64-w64-mingw32 --enable-unicode --without-libtiff --without-libjpeg --with-expat=builtin --with-libpng=builtin --disable-fsvolume
$ make
/home/alex_buz/wx3/bk-deps g++ -c -o netlib_socket.o -I./.pch/wxprec_netlib -D__WXMSW__ -DWXBUILDING -I./src/png -I./src/zlib -I./src/regex -I./src/expat/lib -DwxUSE_GUI=0 -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -I/home/alex_buz/wx3/lib/wx/include/msw-unicode-static-3.0 -I./include -DWX_PRECOMP -O2 -fno-strict-aliasing ./src/common/socket.cpp
./src/common/socket.cpp: In member function ‘wxSocketEventFlags
wxSocketImpl::Select(wxSocketEventFlags, const timeval*)’:
./src/common/socket.cpp:1343:73: error: cannot convert ‘timeval*’ to ‘PTIMEVAL {aka __ms_timeval*}’ for argument ‘5’ to ‘int select(int, fd_set*, fd_set*, fd_set*, PTIMEVAL)’
const int rc = select(m_fd + 1, preadfds, pwritefds, &exceptfds, &tv);
^
make: *** [Makefile:29796: netlib_socket.o] Error 1
Google search gave some hints that it's related to boost.
Any way to resolve it?
Both values are different structures, because the members are of different type. Look at the definition code of them.
You cant convert them => make an instance and set the members.
I am writing a small app on Mac 10.7.5 with gcc47 via macports in Eclipse CDT to learn the new features in C++11. I have a large amount of code compiling, linking and running. When I add the call to "async" I get a linker error. The most simple program that will reproduce the link error follows. Thanks in advance for any help.
#include <iostream>
#include <future>
using namespace std;
void bar()
{
cout << "!!!Hello World!!!" << endl;
}
int main() {
future<void> f1(async(bar));
return 0;
}
The output is:
21:56:46 **** Incremental Build of configuration Debug for project Hello ****
make all
Building file: ../src/Hello.cpp
Invoking: GCC C++ Compiler g++ -D__GXX_EXPERIMENTAL_CXX0X__ -I/opt/local/include/gcc47/c++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/Hello.d" -MT"src/Hello.d" -o "src/Hello.o" "../src/Hello.cpp"
Finished building: ../src/Hello.cpp
Building target: Hello
Invoking: MacOS X C++ Linker g++ -o "Hello"
./src/Hello.o Undefined symbols for architecture x86_64:
"___emutls_v._ZSt11__once_call", referenced from:
void std::call_once<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >,
std::reference_wrapper<bool> >(std::once_flag&, void
(std::__future_base::_State_base::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const&&,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >&&,
std::reference_wrapper<bool>&&) in Hello.o
void std::call_once<void (std::thread::*)(), std::reference_wrapper<std::thread> >(std::once_flag&, void
(std::thread::*&&)(), std::reference_wrapper<std::thread>&&) in
Hello.o "___emutls_v._ZSt15__once_callable", referenced from:
void std::call_once<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >,
std::reference_wrapper<bool> >(std::once_flag&, void
(std::__future_base::_State_base::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&),
std::__future_base::_State_base* const&&,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >&&,
std::reference_wrapper<bool>&&) in Hello.o
void std::call_once<void (std::thread::*)(), std::reference_wrapper<std::thread> >(std::once_flag&, void
(std::thread::*&&)(), std::reference_wrapper<std::thread>&&) in
Hello.o
void std::__once_call_impl<std::_Bind_simple<std::_Mem_fn<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()>&, bool&)>
(std::__future_base::_State_base*,
std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base,
std::__future_base::_Result_base::_Deleter> ()> >,
std::reference_wrapper<bool>)> >() in Hello.o
void std::__once_call_impl<std::_Bind_simple<std::_Mem_fn<void (std::thread::*)()> (std::reference_wrapper<std::thread>)> >() in
Hello.o ld: symbol(s) not found for architecture x86_64 collect2:
error: ld returned 1 exit status make: *** [Hello] Error 1
The information at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54806 and https://trac.macports.org/ticket/36093 suggests that this error is due to a bug in the MacPorts version of GCC. According to https://trac.macports.org/ticket/36093#comment:35 this has been fixed as of r98493 of MacPorts. I would expect that your problem would go away if you updated to that revision of the port repository and then reinstalled GCC.
I'm trying to develop a packet analyzer with CUDA support for pattern matching. I'm using GTK+ for GUI creation but I am not able to compile the GUI file together with the cuda files. How to write makefile for this case?
The project is having two parts: 1. Analyzer 2. GUI
Analyzer consists of many .c,.h files and one .cu file.
GUI part has only one file gui.c
I have included packet_analyzer.h in gui.c.
I tried the following makefile
all: guitest
guitest: gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gcc -lpcap -lpthread `pkg-config --cflags --libs gtk+-2.0` gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gui.o: gui.c
gcc -lpcap -lpthread -c `pkg-config --cflags --libs gtk+-2.0` gui.c
list.o : list.c
gcc -c list.c
queue.o : queue.c
gcc -c queue.c
Word.o : Word.c Word.h
gcc -c Word.c
dictionary.o : dictionary.c
gcc -c dictionary.c
rule.o : rule.c rule.h
gcc -c rule.c rule.h
packet_capturer.o : packet_capturer.c
gcc -lpcap -lpthread -c packet_capturer.c
aho-corasick.o : aho-corasick.c
gcc -lpcap -lpthread -c aho-corasick.c
aho-corasick_cuda.o : aho-corasick_cuda.cu
nvcc -lpcap -lpthread -c aho-corasick_cuda.cu
packet_analyzer.o : packet_analyzer.c
gcc -lpcap -lpthread -c packet_analyzer.c
clean:
rm -rf *o guitest
i end up with the following errors:
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x37): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x86): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xac): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xd5): undefined reference to `cudaMalloc'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xfb): more undefined references to `cudaMalloc' follow
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x132): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x166): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x19d): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x1d1): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x208): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x23c): more undefined references to `cudaMemcpy' follow
aho-corasick_cuda.o: In function `transfer_packets_from_hosttodevice(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x3b1): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x519): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x52b): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x53d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x56b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x58b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5ab): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o: In function `analyze_packets(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x663): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x683): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x6dd): undefined reference to `cudaConfigureCall'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x777): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x78a): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7d5): undefined reference to `Queue_enqueue(Queue*, void*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7f3): undefined reference to `cudaFree'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x802): undefined reference to `cudaFree'
aho-corasick_cuda.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x824): undefined reference to `__cudaUnregisterFatBinary'
aho-corasick_cuda.o: In function `__device_stub__Z14AC_search_CudaPiS_S_S_S_S_S_S_PhiS_(int*, int*, int*, int*, int*, int*, int*, int*, unsigned char*, int, int*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x85c): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x87f): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8a2): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8c5): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8e8): undefined reference to `cudaSetupArgument'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x90b): more undefined references to `cudaSetupArgument' follow
aho-corasick_cuda.o: In function `__sti____cudaRegisterAll_52_tmpxft_00001608_00000000_4_aho_corasick_cuda_cpp1_ii_9958a654()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xa82): undefined reference to `__cudaRegisterFatBinary'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xae3): undefined reference to `__cudaRegisterFunction'
aho-corasick_cuda.o: In function `cudaError cudaLaunch<char>(char*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to `cudaLaunch'
aho-corasick_cuda.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [guitest] Error 1
You need to link with the CUDA runtime library. Add -lcudart to your link command (and CUDA lib path if necessary).
It's the nvcc -lpcap -lpthread $(ANALYZER) -o packet_analyzer.o line that's failing, right? With the -o option, you're telling it to build a complete executable, not just the object files. It needs a main function to do that, which I presume you don't have in any of the $(ANALYZER) files. Instead, try compiling all the sources with the -c flag (like you've done with gcc for gui.c), and then wrap it all together and link it with the other gcc command.
Does anyone know of a language engine (compiler or interpreter, AST, syntax, and basic semantics) but with NO standard library (hopefully not even integers or arithmetic). Is there such a thing? I'd want to be able to implement the standard library in C++. Does such a thing exist?
GCC (and I'm pretty sure a lot of other compilers) lets you build your code without the standard headers and/or libraries, with the -nostdinc (also -nostdinc++ for C++) and -nostdlib flags.
For example:
$ cat t.cpp
#include <iostream>
int main()
{
std::cout << "ouch" << std::endl;
}
$ g++ -nostdinc t.cpp # Failed compilation
t.cpp:1:20: error: no include path in which to search for iostream
t.cpp: In function ‘int main()’:
t.cpp:5:5: error: ‘cout’ is not a member of ‘std’
t.cpp:5:28: error: ‘endl’ is not a member of ‘std’
$ g++ -nostdinc++ t.cpp # Failed compilation
t.cpp:1:20: fatal error: iostream: No such file or directory
compilation terminated.
$ g++ -nostdlib t.cpp # Compiles, but fails to link
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400158
/tmp/ccPPO3l6.o: In function `main':
t.cpp:(.text+0xa): undefined reference to `std::cout'
t.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
t.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
t.cpp:(.text+0x1c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccPPO3l6.o: In function `__static_initialization_and_destruction_0(int, int)':
t.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
t.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()'
t.cpp:(.text+0x54): undefined reference to `__dso_handle'
t.cpp:(.text+0x61): undefined reference to `__cxa_atexit'
collect2: ld returned 1 exit status
This is used for building things like kernel code that can't use the C library.
Good luck with implementing a standard library, that's an enormous task.