小编lil*_*tt8的帖子

Antlr4与C++和CMake

我正在尝试将antlr4与C++一起使用.我的根目录中有以下CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(demo VERSION 0.1 DESCRIPTION "demo")

include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_CXX_STANDARD 17)
#############################################################################
# ANTLR SPECIFIC CMAKE COMMANDS
# This is derived from: https://github.com/blorente/antlr-4.7-cpp-cmake-base
#############################################################################
# Set the ocation of the JAR.
set(ANTLR4CPP_JAR_LOCATION ${CMAKE_SOURCE_DIR}/antlr/jar/antlr.jar)

# Add external build for antlrcpp.
include (${CMAKE_SOURCE_DIR}/antlr/runtime/ExternalAntlr4Cpp.cmake)

# add antrl4cpp artifacts to project environment.
include_directories( ${ANTLR4CPP_INCLUDE_DIRS} )
link_directories( ${ANTLR4CPP_LIBS} )
# message(WARNING "Found antlr4cpp libs: ${ANTLR4CPP_LIBS} and includes: ${ANTLR4CPP_INCLUDE_DIRS} ")

# Build the lexer/parser .h/.cpp files off the g4 grammar files.
antlr4cpp_process_grammar(demo demoparser
    ${CMAKE_SOURCE_DIR}/grammar/DemoLexer.g4
    ${CMAKE_SOURCE_DIR}/grammar/DemoParser.g4)

# …
Run Code Online (Sandbox Code Playgroud)

cmake clion

7
推荐指数
1
解决办法
1217
查看次数

Boost :: graph Dijkstra和自定义对象和属性

我想使用boost的dijkstra算法(因为我在程序的其他部分使用了boost).我遇到的问题是添加自定义对象(我相信它们被称为property)adjacency_list.

基本上我有一个自定义边缘类,它维护有关边缘和通过它连接的顶点的各种信息.我想用我所需的边缘属性存储我的自定义数据对象adjaceny_list

我已经成功实现了提升提供的玩具示例.我试图使用自定义属性无济于事(提升示例,提升属性).我只是将我的VEdge数据结构封装在一个结构或其他东西中,我只需要能够检索它.但我无法弄清楚如何将自定义数据结构包含在boost adjaceny_list结构中.

在我的情况下,我有以下程序:

Main.cpp的:

#include <iostream>
#include <fstream>
#include "dijkstra.h"
#include <vector>

int
main(int, char *[])
{
  // Generate the vector of edges from elsewhere in the program
  std::vector<VEdge*> edges; //someclass.get_edges();

  td* test = new td(edges);
  test->run_d();

  test->print_path();

  return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

Dijkstra.cpp:

#include <iostream>
#include <fstream>
#include "dijkstra.h"

using namespace boost;

td::td() {
    kNumArcs = sizeof(kEdgeArray) / sizeof(Edge);
    kNumNodes = 5;
}

td::td(std::vector<VEdge*> edges) {
    // …
Run Code Online (Sandbox Code Playgroud)

c++ boost dijkstra adjacency-list boost-graph

5
推荐指数
1
解决办法
1200
查看次数

CMake在include_directories中找不到正确的头文件/包含文件

当我尝试编译时,再次出现“架构x86_64的未定义符号”错误。我已经做了很多尝试,超出了我在这篇文章中实际记录的范围(因为我已经忘记了所有尝试过的内容)。这是一个非常简单的设置,使用CMake轻松编译。

当我对此进行make时,效果很好。但我想将其转换为CMake以实现互操作性。如您所见,我在一些地方抛出了“ $ {HEADERS}”变量,我已经尝试了很多放置它的位置,但是我不断遇到错误。根据我放置$ {HEADER}的位置,它还可以从技术上生成错误“错误:生成多个输出文件时无法指定-o”(如果它位于target_link_library声明中,则适用)。

我有2个文件夹:

Root
    Headers (contains all .h files)
    Source (contains all .cc/.cpp/.c files) (and also a CMakeLists.txt)
CMakeLists.txt
Run Code Online (Sandbox Code Playgroud)

我的根CMakeLists.txt包含以下内容:

cmake_minimum_required(VERSION 2.8.4)
project(Framework)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_compile_options("-v")

add_subdirectory(Source)

#Variables for making my life easier and adding the headers
set(H Headers)
include_directories(${H})
set(S Source)
file(GLOB HEADERS
#Add any file in the headers dir
"${H}/*"
)

# Create a variable to use for main.cc
set(MAIN ${S}/main.cc ${HEADERS})

# Add the main.cc file and headers
add_executable(Framework …
Run Code Online (Sandbox Code Playgroud)

c++ compilation cmake

4
推荐指数
1
解决办法
8757
查看次数

不了解MapReduce NPE

这是我收到的错误:

    14/02/28 02:52:43 INFO mapred.JobClient: Task Id : attempt_201402271927_0020_m_000001_2, Status : FAILED
java.lang.NullPointerException
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.init(MapTask.java:843)
    at org.apache.hadoop.mapred.MapTask.createSortingCollector(MapTask.java:376)
    at org.apache.hadoop.mapred.MapTask.access$100(MapTask.java:85)
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.<init>(MapTask.java:584)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:656)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
    at org.apache.hadoop.mapred.Child.main(Child.java:262)
Run Code Online (Sandbox Code Playgroud)

我已经注释了我的代码,基本上采用了典型的LongWritable和Text,然后我只输出一个常量IntWritable 1和一个空的天气类(自定义类):

这是我的mapper类:

public class Map extends Mapper<LongWritable, Text, IntWritable, Weather> {

private IntWritable id = new IntWritable(1);
private Weather we = new Weather();

public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    //String s;
    //String line = value.toString();

    //int start[] …
Run Code Online (Sandbox Code Playgroud)

java generics hadoop mapreduce cloudera

3
推荐指数
1
解决办法
2601
查看次数

反射一个只有包级访问权限的类

我不太确定如何反映一个只有包级访问权限的类。我知道如何反映任何具有公共访问权限的类,但我无法弄清楚如何反映以下示例:

public class Main {
    public static void main(String[] args) {
        test t = new test();
        Constructor<one.oneimpl> con = one.oneimpl.class.getDeclaredConstructor(test.class);
        oneimpl o = con.newInstance(t);
        o.doIt();
    }
}
Run Code Online (Sandbox Code Playgroud)

======================

package one;
// implementation class for mimicking android api
class oneimpl extends one {
    Test mTest;
    private oneimpl(test t){mTest = t;}
    public void doIt(){System.out.println("Do It!");}
    public void dontDoit(){System.out.println("Don't Do It!");}
}
Run Code Online (Sandbox Code Playgroud)

======================

package one;
// abstract class for mimicking android api
abstract class one {
    public void doIt();
    public void dontDoIt();
} …
Run Code Online (Sandbox Code Playgroud)

java reflection

3
推荐指数
1
解决办法
1707
查看次数

c ++中的长整数模运算

我正在研究大数的素数分解(主要是项目3 @项目Euler.我需要对声明为long long的数字使用模数.每次我尝试模拟这个巨大的数字我得到一个浮点异常.任何帮助都将是非常感谢.谢谢.

我通过gdb运行了这个,看看发生了什么.以下是我的代码.在这一点上,这是非常粗略的逻辑. 请不要给我这个问题的答案.我很乐意接受帮助,使这更好​​,只是请不要给我直接的答案.谢谢 :)

long factor(long number) {
  string br = "\n\r";
  long x = 0;
  /*this modulus variable is an attempt
  to move the answer into a long long container
  to see if that solves my floating point exception,
  it didn't*/
  long long modulus;

  while(x <= number) {
    modulus = number % x;
    if(modulus == 0) {
      cout << number/x << br;
      return factor(number/x);
    }//if number % x
    else {
      return x;
    }//else
    x++; …
Run Code Online (Sandbox Code Playgroud)

c++ primes prime-factoring

2
推荐指数
1
解决办法
7106
查看次数

cmake简单的子目录不包括文件

我已经阅读并尝试了几乎每个教程/维基/ SO帖子,页面,我能找到的片段,以使这个CMAKE工作....

我有一个超级简单的目录结构:

ROOT/
|- CMakeLists.txt
|- main.cpp
|- sub/
    |-CMakeLists.txt
    |-subx/
        |-CMakeLists.txt
        |-subx.h
        |-subx.cpp
    |-suby/
        |-CMakeLists.txt
        |-suby.h
        |-suby.cpp
Run Code Online (Sandbox Code Playgroud)

main.cpp是一个超级简单的cpp程序:

//omitting all unnecessary code
int main() {
    subx s;
    s.defined_method();
    s.another_defined_method(1);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

你可以假设,为了每个人的缘故,subx和suby定义是正确的并且工作正常,因为它们在我手动编译时会这样做.

当我通过CMake编译时,我收到以下错误:

"/path/to/cmake" --build /path/to/Debug --target CS220_Project -- -j 4
Linking CXX executable simple_project
Undefined symbols for architecture x86_64:
  "subx::defined_method()", referenced from:
      _main in main.cpp.o
  "subx::another_defined_method(int)", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code …
Run Code Online (Sandbox Code Playgroud)

c++ cmake clion

2
推荐指数
1
解决办法
1733
查看次数

Java连续方法调用

所以我在很多地方看到过调用类的方法:

SomeClass obj = new SomeClass();
obj.addX(3).addY(4).setSomething("something").execute();
Run Code Online (Sandbox Code Playgroud)

我不认为我完全理解它是如何工作的.每个方法是否彼此独立,因此以上等于:

obj.addX(3);
obj.addY(4);
obj.addSomething("something");
obj.execute();
Run Code Online (Sandbox Code Playgroud)

或者他们是否以其他方式设计他们的类结构.如果他们是如何设计他们的类来支持这个?

此外,它有一个特定的名称?或者这只是在类上调用方法?

java methods

0
推荐指数
1
解决办法
601
查看次数

将null作为参数发送到Java中的方法

我在下面有一个相当简单的测试用例.我可以向构造函数发送空值而没有任何问题或错误,但是当我尝试向方法发送空值时,它会出错:( error: incompatible types: <null> cannot be converted to int或者预期的任何类型).我不确定为什么会发生这种情况,而且我在很多地方看到过发送空值是可以接受的做法.在所有现实中我只需要空值,以便我可以将此示例泵入Soot和Spark进行静态分析,因此除了Spark-static分析中入口点的语义必要性之外,发送到方法的实际参数是无关紧要的.

public class Test {
    public Test(Object var1, Object var2) {
        //do irrelevant stuff here with var1 and var2
    }

    public void api1(int x, int y) {
        // do irrelevant stuff with x and y
    }

    public List<String> api2(String x, int y, boolean a) {
        // do irrelevant stuff with x, y, and a and return a new ArrayList<String>()
    }
}

public class Main {
    public static void main(String[] args) …
Run Code Online (Sandbox Code Playgroud)

java methods null static-analysis parameter-passing

0
推荐指数
1
解决办法
112
查看次数