Compiling & building CPP using LLVM (Clang) on Windows10 - c++

I installed LLVM on a clear Windows 10 machine, without anything else. I installed the ARMCompiler6.14.1. I have a simple cpp for testing:
#include <stdio.h>
#include <iostream>
#include <vector>
int main(void) {
int counter = 0;
counter++;
printf("counter: %d", counter);
std::cout << std::endl;
printf("c++14 output");
std::cout << std::endl;
std::vector<int> vect{1, 2, 3, 4, 5};
for (auto & el : vect)
std::cout << "-" << el << std::endl;
return counter;
}
When I compile this with following line I get errors:
"C:\Program Files\LLVM\bin\clang++.exe" -MD -x c++ "C:\Test\test.cpp" -target armv7a-none-eabi "-IC:\Program Files\ARMCompiler.6.14.1\include"
The error is:
test.cpp 2:10:fatal error: 'iostream' file not found
When I compile this with following line I get an windows executable which runs:
"C:\Program Files\LLVM\bin\clang++.exe" -MD -x c++ "C:\Test\test.cpp"
Since I checked that in the LLVM\bin is anything from the developer.arm.com package (ARMcompiler 6.14.1), I think that I should get an a.out for ARM, but I do not. When I checked the generated object file with:
"C:\Program Files\LLVM\bin\llvm-objdump.exe" -f test.o
I get following:
test.o file format elf32-littlearm
arhitecture: arm
start adress: 0x00000000
which means the object file is correctly generated for ARM, but I did not get an executable a.out for ARM.
What am I missing? How should I compile a simple test program to get it cross-compiled for ARM? Should I get the binutil from GCC for the Clang to create ARM executables?

Related

How to use boost when installed via homebrew?

This might be a very basic question, but this is my first time with such an issue. I am using an M1 macOS Big Sur. I am trying to run boost libraries for my program. I have installed boost on my device using arch -arm64 brew install boost.
When I try to compile the following program:
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int128_t boost_product(long long A, long long B)
{
int128_t ans = (int128_t)A * B;
return ans;
}
int main()
{
long long first = 98745636214564698;
long long second = 7459874565236544789;
cout << "Product of " << first << " * " << second
<< " = \n"
<< boost_product(first, second);
return 0;
}
with
$ g++ --version
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I get the following error:
boost.cpp:1:10: fatal error: 'boost/multiprecision/cpp_int.hpp' file not found
#include <boost/multiprecision/cpp_int.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
This is what I see when I go into /opt/homebrew/lib:
cmake libboost_log-mt.dylib libboost_serialization.a libgettextsrc-0.21.dylib
gcc libboost_log.a libboost_serialization.dylib libgettextsrc.dylib
gettext libboost_log.dylib libboost_stacktrace_addr2line-mt.a libgmp.10.dylib
libasprintf.0.dylib libboost_log_setup-mt.a libboost_stacktrace_addr2line-mt.dylib libgmp.a
libasprintf.a libboost_log_setup-mt.dylib libboost_stacktrace_addr2line.a libgmp.dylib
libasprintf.dylib libboost_log_setup.a libboost_stacktrace_addr2line.dylib libgmpxx.4.dylib
libboost_atomic-mt.a libboost_log_setup.dylib libboost_stacktrace_basic-mt.a libgmpxx.a
libboost_atomic-mt.dylib libboost_math_c99-mt.a libboost_stacktrace_basic-mt.dylib libgmpxx.dylib
...
When I cd into cmake, I see that there are a bunch of Boost_...-prefixed files.
It looks like I have boost on my computer, but how do I use it in my program and compile it with g++?
I figured out that the homebrew was adding files to /opt/homebrew/Cellar/boost/1.79.0_1/include/boost. Once the location was identified, I simply compiled by code with flag
g++ -I/opt/homebrew/Cellar/boost/1.79.0_1/include/boost ...
And made sure my include statements referenced the appropriate .hpp files.

using c++ Boost in a makefile

I have a simple C++ program which I compile with clang using the Boost library and with C++14 support.
I use the following command to compile my sample.cpp file and it works fine:
clang++ -g -std=c++1y -I$BOOST_ROOT sample.cpp -o sample
where $BOOST_ROOT is the path to where I downloaded and extracted the boost zip file.
$BOOST_ROOT=/usr/local/boost_1_66_0/
When I try to compile the same sample.cpp file with a makefile, it doesn't work.
This is what my makefile looks like:
sample: sample.cpp
clang++ -g -std=c++1y -I$BOOST_ROOT sample.cpp -o sample
Running make command, I get the error:
Sample.cpp:9:10: fatal error: 'boost/format.hpp' file not found
#include <boost/format.hpp>
^~~~~~~~~~~~~~~~~~
1 error generated.
And here is the sample.cpp
//
// sample.cpp
//
//
#include <iostream>
#include <boost/format.hpp>
using namespace std;
int main()
{
std::cout << "Enter your first name: " << std::endl;
std::string firstName;
std::cin >> firstName;
std::cout << "Enter your surname: " << std::endl;
std::string surname;
std::cin >> surname;
auto formattedName = str( boost::format("%1% %2%"s) % firstName % surname );
std::cout << "You said your name is: " << formattedName << std::endl;
return 0;
}
CONSOLE OUTPUT
MacBook-Air:Listing_1_7 userd43f$ make
c++ sample.cpp -o sample
sample.cpp:9:10: fatal error: 'boost/format.hpp' file not found
#include <boost/format.hpp>
^~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [sample] Error 1
MacBook-Air:Listing_1_7 userd43f$ ls $BOOST_ROOT
INSTALL boost boost.png bootstrap.sh index.html rst.css
Jamroot boost-build.jam boostcpp.jam doc libs status
LICENSE_1_0.txt boost.css bootstrap.bat index.htm more tools
The problem was that there were spaces instead of a tab in the command-line of my makefile.
BOOST_ROOT := /usr/local/boost_1_66_0
BOOST_INC := ${BOOST_ROOT}/include
sample: sample.cpp
clang++ -g -std=c++1y -I$(BOOST_ROOT) sample.cpp -o sample
In the last line just before clang++ command I was using spaces instead of a TAB. I replaced all the spaces with a single TAB before clang++, and also I needed to put the BOOST_ROOT inside the parentheses as (mentioned by #MaximEgorushkin)
Then it started picking up the right command, as shown in the output below:
MacBook-Air:Listing_1_7 userd43f$ make
clang++ -g -std=c++1y -I/usr/local/boost_1_66_0 sample.cpp -o sample
Boost root directory normally has include and lib directories in it.
It should probably be:
BOOST_ROOT := /usr/local/boost_1_66_0
BOOST_INC := ${BOOST_ROOT}/include
sample: sample.cpp
clang++ -g -std=c++1y -I${BOOST_INC} sample.cpp -o sample

c++ hello world throws Segmentation fault - MinGW, Netbeans

Set up MinGW and Netbeans. Only working withe othere IDE's and compilers in before. My machine is x64 win7x64. I'm not shure if I only installed the 32bit version of MinGW.
Compiling a simpel Helle World in x64 leeds to:
g++ -m64 -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d"
-o build/Debug/MinGW-Windows/main.o main.cpp
//Message: sorry, unimplemented: 64-bit mode not compiled in
The win32 Version compiles fine.
// ---
g++ -m32 -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d"
-o build/Debug/MinGW-Windows/main.o main.cpp
// Compiles without any error...
Starting the 32-Version it prints only one message and terminats withe a segmentation fault before returning from first std:cout. Using ftream, to make a file output same error occures.
The demo-Programm of netbeans "Welcome" throws the same exceptions.
#include <cstdlib>
#include <iostream> // EDIT! (worked at this post long time sry.)
using namespace std;
int main(int argc, char** argv) {
int i = 0; // for making shure, program is working before calling fs.open
std::cout << "hello world blubb" << endl; // this one shows up its message at consol.
//programm aborded.
std::cout << "Now again" << endl; // this on is never reached.
return 0;
}
Errormessages:
Signal received: SIGSEGV ( Segmentation fault )
For programm cppapplication_1 pid 7972
You may discard...
Errormessage windows:
cppapplication_1.exe does not work.
Where can I start my serach? Compiler? some dlls? Dependency Walker?
Thx for any comment =).
Cutton

llvm-g++ compile "hello world" error: internal compiler error: Segmentation fault

I am quite new to c++,and this is my development configuration:
llvm 3.5
gcc+ 4.8
ubuntu 14.04 64bit
eclipse 4.3
This is a "hello world" content generated by eclipse
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
In the beginning,eclipse refuses to compile and complain:
Program "llvm-g++" not found in PATH
Program "llvm-gcc" not found in PATH
after I made two symbolic links:
sudo ln -s /usr/bin/llvm-g++-4.8 /usr/bin/llvm-g++
sudo ln -s /usr/bin/llvm-gcc-4.8 /usr/bin/llvm-gcc
Eclipse starts to compile,but give me these errors:
Info: Internal Builder is used for build
llvm-g++ -O0 -emit-llvm -g3 -Wall -c -fmessage-length=0 -o src/HelloWorld.bc ../src /HelloWorld.cpp
*** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins.
Event | Plugins
PLUGIN_FINISH_UNIT | dragonegg
PLUGIN_FINISH | dragonegg
PLUGIN_START_UNIT | dragonegg
PLUGIN_ALL_IPA_PASSES_END | dragonegg
../src/HelloWorld.cpp: In function ‘main’:
../src/HelloWorld.cpp:13:10: internal compiler error: Segmentation fault
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
^
Please tell me what I did wrong here?

Linker error when compiling a program that uses spidermonkey

I've been trying to learn spidermonkey and so have written the following code, adapted from this guide and while the program compiles properly, I get the following error during linking:
/usr/bin/ld: cannot open linker script file symverscript: No such file or directory
I'm using 64-bit Ubuntu 13.10, and here is the code (seems irrelevant to the problem, but can't hurt)
#include <jsapi.h>
#include <iostream>
#include <string>
int main()
{
std::string script = "var x = 10;x*x;";
jsval rval;
JSRuntime* runtime = 0;
JSContext* context = 0;
JSObject* globalob = 0;
if((!(runtime = JS_NewRuntime(1024L*1024L, JS_NO_HELPER_THREADS)))||
(!(context = JS_NewContext(runtime, 8192)))||
(!(globalob = JS_NewObject(context, NULL, NULL, NULL))))
{
return 1;
}
if(!JS_InitStandardClasses(context, globalob))
{
return 1;
}
if(!JS_EvaluateScript(context,globalob,script.data(),script.length(),"script",1,&rval))
{
return 1;
}
std::cout << JSVAL_TO_INT(rval) << "\n";
JS_DestroyContext(context);
JS_DestroyRuntime(runtime);
JS_ShutDown();
return 0;
}
compiled with the command
g++ main.cpp -o out $(js24-config --cflags --libs | tr "\n" " ")
Try to write this command instead,
g++ main.cpp -o main -I/usr/local/include/js/ -L/usr/local/lib/ -lmozjs1.8.5
regarding the path I wrote above, you must write your own path which include the library and JSAPI.h file included in,
And the last term is spidermonkey library, you will find it in lib folder, for me it exists in /usr/local/lib