I'm attempting to compile shapeit - https://github.com/odelaneau/shapeit4
The most recent gcc I have available is 5.3.1
When I run make, the following error trace is shown:
g++ -std=c++11 -O3 -mavx2 -mfma -c src/main.cpp -o obj/main.o -Isrc -I/local/src/htslib-1.3.2/htslib -I/local/include/boost
In file included from src/phaser/phaser_header.h:29:0,
from src/main.cpp:23:
src/models/haplotype_segment_single.h: In member function ‘bool
haplotype_segment_single::TRANS_DIP_MULT()’:
src/models/haplotype_segment_single.h:556:25: error: call of overloaded ‘isnan(double&)’ is ambiguous
return (isnan(sumDProbs) || isinf(sumDProbs) || sumDProbs < numeric_limits<double>::min());
^
In file included from /usr/include/features.h:375:0,
from /opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/x86_64-redhat-linux/bits/os_defines.h:39,
from /opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/x86_64-redhat-linux/bits/c++config.h:2255,
from /opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/bits/stl_algobase.h:59,
from /opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/vector:60,
from src/utils/otools.h:26,
from src/phaser/phaser_header.h:27,
from src/main.cpp:23:
/usr/include/bits/mathcalls.h:235:1: note: candidate: int isnan(double)
__MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
^
In file included from /opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/random:38:0,
from /opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/bits/stl_algo.h:66,
from /opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/algorithm:62,
from src/utils/otools.h:35,
from src/phaser/phaser_header.h:27,
from src/main.cpp:23:
/opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/cmath:634:3: note: candidate: constexpr bool std::isnan(long double)
isnan(long double __x)
^
/opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/cmath:630:3: note: candidate: constexpr bool std::isnan(double)
isnan(double __x)
^
/opt/rh/devtoolset-4/root/usr/include/c++/5.3.1/cmath:626:3: note: candidate: constexpr bool std::isnan(float)
isnan(float __x)
^
In file included from src/phaser/phaser_header.h:29:0,
from src/main.cpp:23:
I attempted to replace the isnan(sumDProbs) call with std::isnan(sumDProbs) or with ::isnan(sumDProbs). Both of these finished compiling, but the resulting binary threw an Illegal Instruction. Is there a different namespace I should be using to clarify the isnan call?
This is el7 with the devtoolset-4 activated because el7 has gcc 4.8.5. I activate using scl enable devtoolset-4 -- bash and then run the compile commands.
I do not have a using namespace std; included.
This is the line that's throwing the ambiguous error:
https://github.com/odelaneau/shapeit4/blob/master/src/models/haplotype_segment_single.h#L556
bool haplotype_segment_single::TRANS_HAP() {
sumHProbs = 0.0f;
unsigned int curr_rel_segment_index = curr_segment_index-segment_first;
yt = M.getForwardTransProb(AlphaLocus[curr_rel_segment_index - 1], curr_abs_locus);
nt = 1.0f - yt;
//float fact1 = M.nt[curr_abs_locus-1] / AlphaSumSum[curr_rel_segment_index - 1];
float fact1 = nt / AlphaSumSum[curr_rel_segment_index - 1];
fill_n(HProbs, HAP_NUMBER*HAP_NUMBER, 0.0f);
for (int h1 = 0 ; h1 < HAP_NUMBER ; h1++) {
//float fact2 = (AlphaSum[curr_rel_segment_index-1][h1]/AlphaSumSum[curr_rel_segment_index-1]) * M.t[curr_abs_locus - 1] / n_cond_haps;
float fact2 = (AlphaSum[curr_rel_segment_index-1][h1]/AlphaSumSum[curr_rel_segment_index-1]) * yt / n_cond_haps;
for (int k = 0 ; k < n_cond_haps ; k ++) {
for (int h2 = 0 ; h2 < HAP_NUMBER ; h2++) HProbs[h1*HAP_NUMBER+h2]+=((Alpha[curr_rel_segment_index-1][k*HAP_NUMBER + h1]*fact1 + fact2)*prob[k*HAP_NUMBER+h2]);
}
sumHProbs += HProbs[h1*HAP_NUMBER+0]+HProbs[h1*HAP_NUMBER+1]+HProbs[h1*HAP_NUMBER+2]+HProbs[h1*HAP_NUMBER+3]+HProbs[h1*HAP_NUMBER+4]+HProbs[h1*HAP_NUMBER+5]+HProbs[h1*HAP_NUMBER+6]+HProbs[h1*HAP_NUMBER+7];
}
return (isnan(sumHProbs) || isinf(sumHProbs) || sumHProbs < numeric_limits<float>::min());
}
Do I need to change this line:
return (isnan(sumHProbs) || isinf(sumHProbs) || sumHProbs < numeric_limits<float>::min());
to
return (isnan((double)sumHProbs) || isinf(sumHProbs) || sumHProbs < numeric_limits<float>::min());
The warning is:
/home/dronz/OF/apps/myApps/HexMap/src/HexMap.cpp:48:5: warning:
this ‘if’ clause does not guard... [-Wmisleading-indentation]
if (toHexSize < 1)
^~
/home/dronz/OF/apps/myApps/HexMap/src/HexMap.cpp:51:2: note: ...
this statement, but the latter is misleadingly indented as
if it were guarded by the ‘if’
MapTileSizeAtZoom = toHexSize;
^~~~~~~~~~~~~~~~~
And the code is this:
if (toHexSize < 1)
toHexSize = 1;
MapTileSizeAtZoom = toHexSize;
I could see it being misleading if the MapTileSizeAtZoom ... line were indented more, but it's at the same level of indentation as the 'if', so that seems correct to me.
I thought maybe there were extra spaces and/or tabs floating around, but I trimmed out any needless whitespace characters after text, and that made no difference.
I thought maybe it was confused by the blank line, but taking it out did not stop the warning.
Furthermore, before it in the same .cpp file is this code, which it does not warn about:
if (toHexSize < 1)
toHexSize = 1;
HexInfo centerOnHex;
if (SelectedHex.type != -1)
Why does it warn about one (at all), and why doesn't it warn about the other, whether or not this is a GCC bug, and what can I do to avoid it?
Code
#include "HexMap.h"
#include <algorithm>
#include <cmath>
//--------------------------------------------------------------
HexMap::HexMap()
{}
//--------------------------------------------------------------
int HexMap::SetZoom(int toHexSize)
{
if (toHexSize < 1)
toHexSize = 1;
HexInfo centerOnHex;
if (SelectedHex.type != -1)
{
// Center map on the selected hex.
centerOnHex = SelectedHex;
}
else
{
// Center map on current center of viewpoint.
centerOnHex = GetHex(
MapFrame.x + MapFrame.getWidth() / 2,
MapFrame.y + MapFrame.getHeight() / 2 );
if ((centerOnHex.x > WORLDMAPWIDTH) || (centerOnHex.x < 0))
centerOnHex.x = WORLDMAPWIDTH / 2;
if ((centerOnHex.y > WORLDMAPHEIGHT) || (centerOnHex.y < 0))
centerOnHex.y = WORLDMAPHEIGHT / 2;
}
setHexDisplaySize(toHexSize);
// Center map:
HexOriginX = MapFrame.x + MapTileWidth * 0.25f;
HexOriginY = MapFrame.y + MapTileHeight * 0.5f;
ViewPosOnWorld.set(
centerOnHex.x - (MapFrame.getWidth() / 2) / MapTileWidth,
centerOnHex.y - (MapFrame.getHeight() / 2) / MapTileHeight);
return 0;
}
//--------------------------------------------------------------
void HexMap::setHexDisplaySize(int toHexSize)
{
if (toHexSize < 1)
toHexSize = 1;
MapTileSizeAtZoom = toHexSize;
MapTileWidth = MapTileSizeAtZoom * 1.5f; // hex x-spacing is 1.5 * r
MapTileHeight = MapTileSizeAtZoom * 1.73205f; // hex height = sqrt(3*r)
// Size images & hexmask:
MaskWidth = MapTileHeight * 1.154700538; // 1/(sqrt(3)/2)
}
There were spaces used to indent the conditional line 49, but a tab was used to indent line 51.
Tabs are viewed as 8 spaces by GCC. The compiler mistakenly thought that it was aligned with the if statement, even though it didn't seem like that in the editor. It is another reason to be consistent with white space indentation (e.g., by avoiding using any tabs in source code).
I want to know if it is possible to parse GCC builtin functions with clang like
int __builtin_ctz (unsigned int x), int __builtin_clz (unsigned int x). The reason I want to do so is that if I try and parse a C++ file including any of the standard libraries, and with correct include folders, the clang parser code cannot parse standard library files that use builtin functions.
Here is how I configure my C++ parsing:
/* CPP SUPPORT*/
clang::CompilerInvocation & invocation = toolset.getInvocation();
//Adjust for c++
auto& langOpts = toolset.getLangOpts();
langOpts.GNUMode = 1;
langOpts.GNUKeywords = 1;
langOpts.CXXExceptions = 1;
langOpts.RTTI = 1;
langOpts.Bool = 1;
langOpts.CPlusPlus11 = 1;
langOpts.CPlusPlus = 1;
langOpts.CXXOperatorNames = 1;
langOpts.WChar = 1;
langOpts.DeclSpecKeyword = 1;
clang::PreprocessorOptions &PPOpts = toolset.getPreprocessorOpts();
/* CPP SUPPORT*/
invocation.setLangDefaults(langOpts,
clang::InputKind::CXX,
llvm::Triple(targetConfig->Triple),
PPOpts,
clang::LangStandard::lang_cxx11);
The error I receive is:
/usr/include/c++/5/bits/stl_algobase.h use of undeclared identifier '__builtin_clz'
So I have some R code that I wrote that is terribly slow that I wanted to change into C++ code using the Rcpp library. However, I am getting an error message when trying to use it and I cannot seem to locate where the error is occurring. Any help is greatly appreciated!
Here is the original code:
#Necessary packages to run
library(Rcpp)
library(mvtnorm)
#Here are the variables I will be working with
x = c(0.53137100,0.75357474,0.87904120,0.29727488,0.00000000,0.00000000,
0.00000000,0.00000000,0.00000000,0.04059217)
y = c(4.873500,3.896917,1.258215,5.776484,12.475491,5.273784,13.803158,
4.472204,2.629839,6.689242)
front = c(NA,NA,3,NA,NA,NA,NA,NA,9,NA)
all.preds = c(0.596905183,0.027696850,1.005666896,0.007688514,3.900000000)
x = x[!is.na(front)]
y = y[!is.na(front)]
mu = c(all.preds[1],all.preds[3])
sigma = matrix(c(all.preds[2],0,0,all.preds[4]),nrow=2)
z = rmvnorm(10000,mu,sigma)
z[,1] = sapply(z[,1],function(x){max(x,0)})
temp = 1:nrow(z)
for(i in 1:length(temp)){
cond1 = z[i,2]!=min(z[which(z[,1]==z[i,1]),2])
cond2 = z[i,1]!=min(z[which(z[,2]==z[i,2]),1])
for(n in 1:length(x)){
if((z[i,1]>x[n] & z[i,2]>y[n]) | (z[i,1]==x[n] & cond1) | (z[i,2]==y[n] & cond2)){
temp[i] = NA
break
}
}
}
and here is the new Rcpp code that I wrote:
#Necessary packages to run
library(Rcpp)
library(mvtnorm)
#Here are the variables I will be working with
x = c(0.53137100,0.75357474,0.87904120,0.29727488,0.00000000,0.00000000,
0.00000000,0.00000000,0.00000000,0.04059217)
y = c(4.873500,3.896917,1.258215,5.776484,12.475491,5.273784,13.803158,
4.472204,2.629839,6.689242)
front = c(NA,NA,3,NA,NA,NA,NA,NA,9,NA)
all.preds = c(0.596905183,0.027696850,1.005666896,0.007688514,3.900000000)
x = x[!is.na(front)]
y = y[!is.na(front)]
mu = c(all.preds[1],all.preds[3])
sigma = matrix(c(all.preds[2],0,0,all.preds[4]),nrow=2)
z = rmvnorm(10000,mu,sigma)
z[,1] = sapply(z[,1],function(x){max(x,0)})
cppFunction('
int prop(NumericMatrix z, NumericVector x, NumericVector y) {
int nrow = z.nrow();
int n = x.size();
int temp;
for (int i = 0; i < nrow; i++) {
bool cond1 = z(i,2)!=min(z(which(z(,1)==z[i,1]),2));
bool cond2 = z(i,1)!=min(z(which(z(,2)==z[i,2]),1));
for (int j; j < n; j++) {
if((z(i,1)>x[n] && z(i,2)>y[n]) || (z(i,1)==x[n] && cond1) || (z(i,2)==y[n] && cond2)) {
temp[i] = 0;
break;
}
}
}
return temp;
}
')
The error message that I receive is the following:
g++ -m64 -I"C:/PROGRA~1/R/R-30~1.1/include" -DNDEBUG -I"C:/Users/BabakP/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c file7444c995de6.cpp -o file7444c995de6.o file7444c995de6.cpp: In function 'int prop(Rcpp::NumericMatrix, Rcpp::NumericVector, Rcpp::NumericVector)': file7444c995de6.cpp:13:40: error: expected primary-expression before ',' token file7444c995de6.cpp:13:49: warning: left operand of comma operator has no effect [-Wunused-value] file7444c995de6.cpp:13:51: error: 'which' was not declared in this scope file7444c995de6.cpp:14:40: error: expected primary-expression before ',' token file7444c995de6.cpp:14:49: warning: left operand of comma operator has no effect [-Wunused-value] file7444c995de6.cpp:18:15: error: invalid types 'int[int]' for array subscript make: *** [file7444c995de6.o] Error 1
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, :
Error 1 occurred building shared library.
please help me for this errors
code:
u16 ip_defragment(){
u16 result;
fragip_set::iterator i;
IP_FRAGMENTED new_defrag;
IP* pcurpack = (IP*) malloc(cur.len);
memcpy(pcurpack, cur.data, cur.len);
new_defrag.saddr = cur.saddr;
new_defrag.daddr = cur.daddr;
new_defrag.protocol = cur.ip.ppack->protocol;
new_defrag.id = i2i(cur.ip.ppack->id);
i = ip_frags.find(new_defrag);
if(i != ip_frags.end()){
i->packets.insert(pcurpack);
const_cast<u16&>(i->cur_len) += cur.ip.len - cur.ip.hlen;
const_cast<u32&>(i->last_time) = time();
if(!(cur.ip.bmore_fr) && (i->tot_len == 0)){
const_cast<u16&>(i->tot_len) = cur.ip.fr_offs + cur.ip.len;
}
if(i->cur_len == i->tot_len){
for(set<IP*>::iterator k = i->packets.begin(); k != i->packets.end(); k++){
// must copy to another buffer
if(i2i((*k)->frag_off) & IP_OFFMASK){
memcpy(ip_defrag_buffer, *k, (*k)->ihl<<2);
} else {
memcpy(ip_defrag_buffer + (i2i((*k)->frag_off) & IP_OFFMASK) * 8,
*k + ((*k)->ihl<<2), (i2i((*k)->tot_len))-((*k)->ihl<<2));
}
}
IP* defr_ip = (IP*) &ip_defrag_buffer;
defr_ip->tot_len = i2i(i->tot_len);
defr_ip->frag_off = 0;
result = i->tot_len;
ip_frags.erase(i);
return result;
}
return 0;
}
if(!(cur.ip.bmore_fr)){
new_defrag.tot_len = cur.ip.fr_offs + cur.len;
} else {
new_defrag.tot_len = 0;
}
new_defrag.cur_len = cur.ip.len; // with header size
new_defrag.last_time = time();
i = ip_frags.insert(new_defrag).first;
if(i != ip_frags.end())
i->packets.insert(pcurpack);
return 0;
}
compiled project and view only 2 errors similar
line 15 : i->packets.insert(pcurpack);
end line : i->packets.insert(pcurpack);
error with 2 lines : error C2663: 'std::_Tree<_Traits>::insert' : 4 overloads have no legal conversion for 'this' pointer
IntelliSense: no instance of overloaded function "std::set<_Kty, _Pr, _Alloc>::insert [with _Kty=IP *, _Pr=std::less<IP *>, _Alloc=std::allocator<IP *>]" matches the argument list and object (the object has type qualifiers that prevent a match)
please help me?
I had exact same error with std::set, while passing it to a lambda expression:
C2663 'std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::insert': 5 overloads have no legal conversion for 'this' pointer
lambda expression prototype was:
[se1, ele1](auto val) {
/* here I was editing se1 set, but above se1 is passed value type */
}
I have changed to:
[&se1, ele1](auto val) {
/* now since se1 set is sent as reference type above, it is good to edit
changes stays as I expect it to be
*/
}
Now compilation succeeds.
I used with count_if function, which calls the lamda expression for eac element, so the compiler knows that modifications should persist in set se1, which is perfectly logical.
If you desire to have the original set unchanged, then send a copy of it.