Failed to use LLVM libraries on Windows - windows

I've been using the LLVM release build from here https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows. When I build a simple cpp file that references to LLVM library, the compiler crashes. I'm using x64 cl as the compiler.
The command I'm using is roughly: cl -I <llvm include directory> main.cpp %libs% /link /LIBPATH:<llvm lib directory>
The %libs% variable is set to be the output of llvm-config --libnames all --system-libs
Below is the simple CPP program I used.
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
using namespace llvm;
LLVMContext TheContext;
int main()
{
return 0;
}

I have found the problem in my batch script where there's whitespace in the path.

Related

Xcode references wrong path to Mono

I'm trying to compile the c code generated by Embeddinator-4000 but Xcode can't find the specified path to Mono.
These are the headers that are currently giving me problems:
#include <mono/jit/jit.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/object.h>
However these paths work:
#include <Mono/mono-2.0/mono/jit/jit.h>
#include <Mono/mono-2.0/mono/metadata/mono-config.h>
#include <Mono/mono-2.0/mono/metadata/assembly.h>
#include <Mono/mono-2.0/mono/metadata/debug-helpers.h>
#include <Mono/mono-2.0/mono/metadata/object.h>
The problem is that jit.h includes <mono/metadata/appdomain.h> and Xcode can't find it.
Is there a way to alias the framework so I don't have to modify my current install of Mono?
Thanks!

CMake executable runs slower than running in ROOT

I wrote a macro for ROOT with the following libraries:
#include <iostream>
#include <math.h>
#include <vector>
#include <iomanip>
#include <time.h>
#include <stdio.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_odeiv2.h>
//ROOT libraries
#include <TTree.h>
#include <TFile.h>
When running in ROOT with .x script.cpp, it works fine and takes 0.25 seconds to write a root file.
Then, I created an executable using CMake. For that, I created the next CMakeLists files:
This CMakeLists file is outside the directory where the .cpp file is
cmake_minimum_required(VERSION 2.6)
project(CMAKE_TEST)
find_package(GSL)
find_package(ROOT REQUIRED COMPONENTS)
set(CMAKE_CXX_FLAGS "-g++ -O2 -Wall")
set(CMAKE_CXX_FLAGS ${ROOT_CXX_FLAGS})
add_subdirectory(script_sub)
This is the one that is inside (same location as the .cpp file)
include_directories(${CMAKE_TEST_SOURCE_DIR}/script_sub)
link_directories(${CMAKE_TEST_BINARY_DIR}/script_sub)
include(${ROOT_USE_FILE})
set(CORELIBS ${ROOT_LIBRARIES} ${GSL_LIBRARIES} m)
add_executable(script script.cpp)
target_link_libraries(script ${CORELIBS})
CMake creates the Makefile just fine, and then I can run make with no problems either. The issue is that when running the executable by ./script, this writes the root file in 0.92 seconds, i.e., it is slower than running the code in ROOT. The results are correct, and I see no error message.
How is this possible?

GCC inlining failed in call to always_inline [duplicate]

I'm trying to run a Visual Studio cpp project created by a friend of mine. I'm trying to run the file without VS. But I'm getting a list of errors, all in the same format:
inlining failed in call to always_inline '__m256d _mm256_broadcast_sd(const double*)': target specific option mismatch|
It runs correctly in VS with release mode and breaks when run in debug mode.
The includes are as follows:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
# include <omp.h>
#include <chrono>
#include <fstream>
#include <algorithm>
#include <immintrin.h>
using namespace std::chrono;
using namespace std;
and the error is called from here:
double zero = 0;
__m256d acc = _mm256_broadcast_sd(&zero);
Update:
I'm using the this command to run it: g++ -std=c++0x multip.cpp -o multip, is there an additional parameter to add -mavx to the compiler invocation?
"Target specific option mismatch" means that you're missing a feature flag from your GCC invocation. You probably need to add -mavx to your compiler invocation.
If you're intending to run this on your computer only, -march=native will turn on all the feature flags that your own machine supports.

Unable to find Torch header files using nvcc

I'm trying to call some CUDA code from luaJIT (Torch) but I'm running into compiling issues. nvcc seems unable to find my Torch header files. I have CUDA 6.5 and gcc 4.4.7.
nvcc -o im2col -I/deep/u/ibello/torch/include im2col.cu
In file included from /deep/u/ibello/torch/include/THC/THC.h:4,
from utils.h:6,
from im2col.cu:1:
/deep/u/ibello/torch/include/THC/THCGeneral.h:4:23: error: THGeneral.h: No such file or directory
/deep/u/ibello/torch/include/THC/THCGeneral.h:5:25: error: THAllocator.h: No such file or directory
In file included from /deep/u/ibello/torch/include/THC/THC.h:7,
from utils.h:6,
from im2col.cu:1:
/deep/u/ibello/torch/include/THC/THCStorage.h:4:23: error: THStorage.h: No such file or directory
In file included from /deep/u/ibello/torch/include/THC/THC.h:9,
from utils.h:6,
from im2col.cu:1:
im2col.cu includes the following
#include "utils.h"
#include "common.h"
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
where "utils.h" is
#ifndef CUNN_UTILS_H
#define CUNN_UTILS_H
extern "C" { #include <lua.h> }
#include <luaT.h>
#include <THC/THC.h>
THCState* getCutorchState(lua_State* L);
#endif
This is relatively weird since the mentioned files are indeed in the include location I gave to the compiler..
ls /deep/u/ibello/torch/include/THC
THCAllocator.h THCDeviceTensor.cuh THCDeviceTensorUtils-inl.cuh THC.h THCReduce.cuh THCTensorConv.h THCTensorMath.h
THCApply.cuh THCDeviceTensor-inl.cuh THCDeviceUtils.cuh THCReduceAll.cuh THCStorageCopy.h THCTensorCopy.h THCTensorRandom.h
THCBlas.h THCDeviceTensorUtils.cuh THCGeneral.h THCReduceApplyUtils.cuh THCStorage.h THCTensor.h THCTensorSort.h
Any ideas about what I'm doing wrong?
Thx in advance!
It seems that this compile command:
nvcc -o im2col -I/deep/u/ibello/torch/include im2col.cu
did not give the necessary search paths for the compiler to find the header files like THGeneral.h that were located in /deep/u/ibello/torch/include/TH
The solution was to specify a compile command like this:
nvcc -o im2col -I/deep/u/ibello/torch/include -I/deep/u/ibello/torch/include/TH im2col.cu

Getting started with XCode and CUDA

So far I was able to install CUDA and it works fine.
However, I have no idea how to set up XCode for CUDA. And the posts out there seem to be really outdated and full of missing links and files. Also XCode seem to have changed a lot since 2009.
To begin, If I create a new project should I choose "Empty" or "External Build System" or something else?
I suggest using CMake:
1) Install latest CMake from http://www.cmake.org/download/
2) Create CMakeLists.txt and main.cu:
CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(cuda_test)
find_package(CUDA REQUIRED)
cuda_add_executable(cuda_test main.cu)
main.cu (taken from http://thrust.github.io/)
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <algorithm>
#include <cstdlib>
int main()
{
thrust::host_vector<int> h_vec(32 << 20);
std::generate(h_vec.begin(), h_vec.end(), rand);
thrust::device_vector<int> d_vec = h_vec;
thrust::sort(d_vec.begin(), d_vec.end());
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
return 0;
}
3) Use CMake GUI or command line to create a Xcode project out of the above (the following uses the cmake command line)
cmake -G Xcode

Resources