Building antlr4 project in cpp - c++

I'm using antlr4-4.9.2 on Windows 10. I want to use antlr4 in c++, and here's part of my CMakeLists.txt
file(GLOB antlr4-cpp-src
third_party/antlr4-cpp-runtime-4.9.2/src/*.cpp
third_party/antlr4-cpp-runtime-4.9.2/src/atn/*.cpp
third_party/antlr4-cpp-runtime-4.9.2/src/dfa/*.cpp
third_party/antlr4-cpp-runtime-4.9.2/src/misc/*.cpp
third_party/antlr4-cpp-runtime-4.9.2/src/support/*.cpp
third_party/antlr4-cpp-runtime-4.9.2/src/tree/*.cpp
third_party/antlr4-cpp-runtime-4.9.2/src/tree/pattern/*.cpp
third_party/antlr4-cpp-runtime-4.9.2/src/tree/xpath/*.cpp
)
add_library (antlr4-cpp-runtime ${antlr4-cpp-src})
add_executable(MiniSql ${src_dir} src/main.cpp)
target_link_libraries(MiniSql antlr4-cpp-runtime)
But I got 171 errors and warnings. For example, in BufferedTokenStream,
TokenSource *BufferedTokenStream::getTokenSource() const
{
return _tokenSource;
}
got reference to TokenSource is ambiguous.
And many more like this.
What's my problem in the code?

Related

glfwInit() causes segmentation fault with exit code -1073741515 (0xc0000135)

I have been trying to get one my older projects to work which uses some OpenGL code. I am unable to produce a working executable. All that happens is, just by calling glfwInit(), is a segmentation fault:
My best guess is that it somehow doesnt use/find the glfw dll i am trying to use.
Let me explain my current setup:
I have installed glfw using msys2:
pacman -S mingw-w64-x86_64-glfw
I have created a glad header and source file
I wrote a simple cmake-file (which also used to work 2 years ago)
cmake_minimum_required(VERSION 3.23)
project(2DGameEngine)
find_package(glfw3 3.3 REQUIRED)
find_package(OpenGL REQUIRED)
set(CMAKE_CXX_STANDARD 23)
file(GLOB_RECURSE SRCS src/*.cpp src/*.c)
add_executable(2DGameEngine ${SRCS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow")
target_link_libraries(2DGameEngine glfw)
target_link_libraries(2DGameEngine OpenGL::GL)
I used the simplest example I could find:
#include "glad.h"
#include <GLFW/glfw3.h>
#include <iostream>
int main()
{
// glfw: initialize and configure
// ------------------------------
if(!glfwInit()){
std::cout << "error" << std::endl;
exit(1);
}
return 0;
}
Yet I am unable to get rid of the segmentation fault when calling glfwInit(). I assume it has to do with some .dll missing but I have no idea how I could check this. I am very happy for any help.
0xc0000135 is the error you get when your Windows OS could not find a required dll when executing your program. There is a handy site that decodes these types of errors here: https://james.darpinian.com/decoder/?q=0xc0000135
Use this program: https://github.com/lucasg/Dependencies to figure out what dll can not be found and then put that dll in the same folder as the executable or edit your OS PATH environment variable to contain the folder which has that dll.
Here is a good article on how to set the OS PATH environment variable: https://www.computerhope.com/issues/ch000549.htm
There are several other options contained in this Microsoft document which explains how and where your OS searches for dlls: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications

How to properly use CUDA pipeline in Visual studio

Hello I am developing CUDA C++ application. I would like to use CUDA interactive debugger in visual studio but cmake projects seem to be not supported (am I wrong?).
So I am trying to switch from cmake to visual studio project. Hovewer I run into strange problem.
Without any importanta changes in code I have error:
Severity Code Description Project File Line Suppression State
Error Multiple definition of '_ZN4cuda3__48pipelineILNS_3std3__48__detail12thread_scopeE2EE25__barrier_try_wait_parityERNS0_7barrierILS5_2ENS3_18__empty_completionEEEb' in 'x64/Debug/MainPassFunctions.cu.obj', first defined in 'x64/Debug/BiggerMainFunctions.cu.obj' CUDADebugB C:\Users\1\source\repos\CUDADebugB\CUDALINK 1
when I try to use function where argument is defined as :
cuda::pipeline< cuda::thread_scope_block>& pipeline
Begining of my cu file
#include "cuda_runtime.h"
#include <cstdint>
#include <cuda/pipeline>
#include <cooperative_groups.h>
#include <cuda_pipeline.h>
using namespace cooperative_groups;
in cmake project all worked well with cmake as below
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(hello LANGUAGES CXX CUDA)
enable_language(CUDA)
find_package(hdf5 CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -lineinfo -rdc=true -lcudadevrt")
set(CMAKE_CUDA_ARCHITECTURES 80)
add_executable(hello hello.cu )
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
target_link_libraries(${PROJECT_NAME} ${CUDA_LIBRARIES})
target_link_libraries(hello PRIVATE hdf5::hdf5-shared hdf5::hdf5_hl-shared hdf5::hdf5_cpp-shared hdf5::hdf5_hl_cpp-shared)
target_link_libraries(hello PRIVATE GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main)
now my vs studio project settings
What i should change to make it work?
Answer by
rturrado solved the problem
"
It looks like you have two definitions for the same function, one in the MainPassFunctions object file, and the other in the BiggerMainFunctions object file."
So I just fused two files into one.

CMake: Static libraries not linking correctly with second project

Let me preface this by saying I'm quite new to CMake, so please let me know if I'm just misunderstanding something here.
First I'm compiling a static library that acts as a wrapper to an external program (Paraview). The CMakeLists file I use to create this library is like so:
cmake_minimum_required(VERSION 3.3)
project(POP)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY [LIBRARY HOME]/lib/)
set(ParaView_DIR [PARAVIEW HOME]/ParaView-v5.4.1/)
find_package(ParaView REQUIRED COMPONENTS vtkPVPythonCatalyst)
include("${PARAVIEW_USE_FILE}")
if(NOT PARAVIEW_USE_MPI)
message(SEND_ERROR "ParaView must be built with MPI enabled")
endif()
set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/pop_API.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pop_API_vars.h ${CMAKE_CURRENT_SOURCE_DIR}/include/pop_Structures.h ${CMAKE_CURRENT_SOURCE_DIR}/include/wrapper_pop_API.h)
add_library(POP STATIC src/pop_API.cpp src/wrapper_pop_API.cpp src/pop_Adaptor.cpp ${HEADER_FILES})
target_include_directories(POP PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(POP LINK_PUBLIC vtkPVPythonCatalyst)
include(vtkModuleMacros)
include(vtkMPI)
vtk_mpi_link(POP)
This links in a specific Paraview module I need, and some VTK datastructures that are required for that as well.
This CMake file runs just fine, and I can compile the libraries no problem. If I add a Main function to my C++ code and compile it as an executable, that runs no problem as well. So everything seems fine here.
Now, I ultimately want this static library to be called by a second piece of code. To test this I've written a toy C++ project that just calls the main functions of this library
#include "pop_Structures.h"
#include "pop_API.h"
int main()
{
PopGrid* grid;
PopSolution* solution;
a = 1;
b = 2;
int x = POP_INITIALIZE(a, b);
int y = COPROCESS(PopGrid, PopSolution, a, b, a, b);
int z = POP_FINALIZE();
}
The included header files just define the PopSolution and PopGrid structures, as well as the prototypes for the three functions being called. I create the executable for this program using a CMakeLists file that looks like
cmake_minimum_required(VERSION 3.3)
project(CPP_Test)
find_package(MPI REQUIRED)
include_directories(${MPI_CXX_INCLUDE_PATH})
set(HEADER_FILES [LIBRARY HOME]/include/pop_API.h [LIBRARY HOME]/include/pop_Structures.h)
ADD_EXECUTABLE(CPP_TEST CPP_Test.cpp ${HEADER_FILES})
target_include_directories(CPP_TEST PUBLIC [LIBRARY HOME]/include)
target_link_libraries(CPP_TEST[LIBRARY HOME]/lib/libPOP.a)
This CMake also runs just fine, but when I compile it I get a number of undefined reference errors pointing to functions in libPOP.a where I refer to VTK/Paraview data structures and functions. These are not directly defined in the toy code above, but they should be defined in the library, correct? If these structures are all defined when I compile the initial library, why are they not defined when I call that library externally?
Thanks.

Building project with ARUCO fails

I'm trying to build a project with arUco.
I am using openCV v.3.1, which apparently includes aruco. However, I get the error:
opencv2/aruco/dictionary.hpp: No such file or directory
#include "opencv2/aruco/dictionary.hpp"
^
I then downloaded arUco, built it, and tried to build the example described at the bottom of http://www.uco.es/investiga/grupos/ava/node/26 . I get the error:
fatal error: aruco/aruco.h: No such file or directory
#include <aruco/aruco.h>
^
The CMakeLists.txt used is:
cmake_minimum_required(VERSION 2.8)
project(aruco_testproject)
SET(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/lib/cmake/ )
MESSAGE(${CMAKE_MODULE_PATH})
find_package(aruco REQUIRED )
add_executable(aruco_simple aruco_simple.cpp)
target_link_libraries(aruco_simple ${aruco_LIBS})
I've copied Findaruco.cmake to /usr/local/lib/cmake/
If anyone could help, that'd be fantastic. I've been looking for a solution for a while and I feel really stuck. Thanks a lot!
You are missing the include_directories stanza. Also I think the correct variable name suffix for the library should be _LIBRARIES, not _LIBS, but afaik, cmake is unable to enforce any rule with rogue cmake modules, so the best bet is probably to try several common suffixes. That's one of cmake's atrocities.
cmake_minimum_required(VERSION 2.8)
project(aruco_testproject)
SET(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/lib/cmake/ )
MESSAGE(${CMAKE_MODULE_PATH})
find_package(aruco REQUIRED )
add_executable(aruco_simple aruco_simple.cpp)
include_directories(${ARUCO_INCLUDE_DIR} ${ARUCO_INCLUDE_DIRS})
target_link_libraries(aruco_simple ${ARUCO_LIBRARY} ${ARUCO_LIBRARIES})
For the header inclusion, #include <aruco/aruco.h> looks fine, but not #include "opencv2/aruco/xxx".

making boost work with cmake ( fatal error: boost/smart_ptr.hpp: No such file or directory )

After digging for hours on this, I finally need some expert help.
I am new to cmake and trying to port my Visual Studio 2008 project to cmake.
My project uses opencv, qt and boost libraries.
Now I have managed to run simple cmake examples with opencv and qt but I am stuck with boost.
The bottleneck is this: CMake finds the correct boost version, finds the libraries and gives no error while configuration.
But when I try to build the project using make, it gives me:
" fatal error: boost/smart_ptr.hpp: No such file or directory"
Assuming the configuration is done right, cmake should be able to find the boost include directories.
I have set BOOST_ROOT to the correct boost root directory and that's why configuration does not give errors. But what happens while running make? Am I missing something simple here? Need help desperately...
I am sorry if this is a stupid question.
Here's my CMakeLists.txt file:
cmake_minimum_required( VERSION 2.6 )
project (CMakeBoostTutorial)
find_package( Boost 1.46.1 COMPONENTS date_time REQUIRED)
link_directories ( ${Boost_LIBRARY_DIRS} )
include_directories ( ${Boost_INCLUDE_DIRS} )
add_executable ( helloworld helloworld.cc )
target_link_libraries (
helloworld
${Boost_LIBRARIES}
)
And here's my helloworld.cc:
#include <iostream>
#include <stdlib.h>
#include <boost/smart_ptr.hpp>
using namespace std;<br/>
int main(int argc, char *argv[]){
cout<<"Hello World";
return 0;
}
PS: This compiles and runs fine if I remove the #include <boost/smart_ptr.hpp> line