I cannot compile the project "glsl-parser"

Manda Rajo 141 Reputation points
2022-04-08T13:58:33.95+00:00

Official glsl-parser download:
https://github.com/graphitemaster/glsl-parser

As the title says, I cannot compile the project "glsl-parser" because it has 2 errors, about main and about an unresolved external symbol error. How to fix? The second error is the most important to fix because I can temporary fix the first error about main. But both are important to fix because in the end, there shouldn't be error.

191348-new-files.jpg

_build_windows.bat (file that I added):

   set BUILD_FOLDER="_build_windows"  
   cmake -S . -B %BUILD_FOLDER% -A x64  

CMakeLists.txt (file that I added):

   cmake_minimum_required(VERSION 3.7.1)  
     
   ####################################################################################################  
   project(glsl-parser VERSION 1.0)  
   set(BIN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)  
   ####################################################################################################  
     
   # Add any required preprocessor definitions here  
   add_definitions(-DVK_USE_PLATFORM_WIN32_KHR)  
   add_compile_definitions(_CRT_SECURE_NO_WARNINGS)  
   add_compile_definitions(_USE_MATH_DEFINES)  
   add_compile_definitions(_PROJECT_NAME="${PROJECT_NAME}")  
     
   # Gather list of header and source files for compilation  
   file(GLOB_RECURSE CPP_FILES             ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)  
   file(GLOB_RECURSE H_FILES               ${CMAKE_CURRENT_SOURCE_DIR}/*.h)  
   source_group("" FILES                   ${CPP_FILES})  
   source_group("" FILES                   ${H_FILES})  
     
   # Build project, give it a name and includes list of file to be compiled  
   add_executable(${PROJECT_NAME} ${CPP_FILES} ${H_FILES})  
     
   # Different postfix  
   set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX          "_debug")  
   set_target_properties(${PROJECT_NAME} PROPERTIES RELEASE_POSTFIX        "")  
   set_target_properties(${PROJECT_NAME} PROPERTIES MINSIZEREL_POSTFIX     "_minsizerel")  
   set_target_properties(${PROJECT_NAME} PROPERTIES RELWITHDEBINFO_POSTFIX "_relwithdebinfo")  
     
   # Define project properties  
   set_property(TARGET ${PROJECT_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY                ${BIN_DIR})  
   set_property(TARGET ${PROJECT_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY_DEBUG          ${BIN_DIR})  
   set_property(TARGET ${PROJECT_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELEASE        ${BIN_DIR})  
   set_property(TARGET ${PROJECT_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL     ${BIN_DIR})  
   set_property(TARGET ${PROJECT_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${BIN_DIR})  
     
   # Define C++ version to be used for building the project  
   set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)  
   set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)  
     
   # Define C version to be used for building the project  
   set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)  
   set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD_REQUIRED ON)  
     
   ####################################################################################################  
     
   # Startup project  
   set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT glsl-parser)  

I use Visual Studio 2015
To create the Visual Studio Solution "glsl-parser.sln", execute the new added file "_build_windows.bat".

To compile, click that button "Local Windows Debugger", then it will show so many errors (not easy to read), and then click that button "Local Windows Debugger" again to show very clear errors just like in the image below.

According to the following link, the unresolved external symbol error means that an operator delete is missing from external, and I don't believe I can fix it internally because astNode is an external: https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix

191402-glsl-parser-issue.jpg

Developer technologies C++
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Viorel 122.5K Reputation points
    2022-04-08T16:00:47.793+00:00

    Try adding '= delete' to struct astNode:

    private:
        void *operator new(size_t) = delete;
        void operator delete(void *) = delete;
    

    Use the existing main function.

    In Visual Studio you can create a new Console project, add the existing .cpp files and perform some adjustments.

    1 person found this answer helpful.
    0 comments No comments

  2. Manda Rajo 141 Reputation points
    2022-04-08T16:52:10.783+00:00

    Thank you, now I realize it's about memory management, which means that I must come back to this issue one day because it's temporary fixed by replacing them with empty functions, because I don't want memory leaks.

    I tried to replace them with = delete then an error:
    Error location in parser.cpp on #include <string.h>.
    Error C2280 'void glsl::astNode<glsl::astFunction>::operator delete(void *)': attempting to reference a deleted function glsl-parser ...\glsl-parser\parser.cpp

    The big problem here is about memory leak because there are so many warnings like this:
    Warning C4291 'void *glsl::astNode<glsl::astExpression>::operator new(std::size_t,glsl::vector<glsl::astMemory> *) throw()': no matching operator delete found; memory will not be freed if initialization throws an exception

    // Nodes are to inherit from astNode or astCollector
    template <typename T>
    struct astNode {
        void *operator new(size_t size, vector<astMemory> *collector) throw() {
            void *data = malloc(size);
            if (data)
                collector->push_back(astMemory((T*)data));
            return data;
        }
    private:
        void *operator new(size_t) = delete;    // <-- EDIT: If I change it to ... new(size_t) {}; (empty function) then it will cause memory leak but it's just a temporary fix.
        void operator delete(void *) = delete;  // <-- EDIT: If I change it to ... delete(void *) {}; (empty function) then it will cause memory leak but it's just a temporary fix.
    };
    

  3. Manda Rajo 141 Reputation points
    2022-04-08T19:20:51.57+00:00

    My goal:

      1. Just like an application named Blender 3D, it uses Python as an interpreted language, but Python is 31 years old, and that application Blender cannot leave from it anymore because its entire User Interface is build with Python interpreter. So I want to build a programming language (Interpreter, CPU and GPU at the same time), it will be so powerful.
      1. I want to build my own programming language on CPU but 99% close to GPU language (glsl). For example in my engine, when I make a draft for a GPU project, then instead of using C++ as a draft, then I will use my own programming language which will be close to GPU language but it's CPU. I will use header files as common sources between the CPU language & GPU language. It will fasten my developement.
    • That's the reason I wish that this glsl-parser succeed without crash. But it seems impossible to me to fix it then I have to build my own programming language by inspiring from its sources.
    • Who knows, maybe that crash forces me to build my own programming language from scrach by referencing from a working Lexer and I will modify it.

    I found another simpler parser (not glsl)
    https://www.freecodecamp.org/news/the-programming-language-pipeline-91d3f449c919/
    Since it's tiny then I could compile it (done), and without any crash. That's how I can see all the outputs, like trees of nodes of how to build a programming language.

    The reason I show the screenshot below is it's impossible for me to use that glsl-parser because it always crashes with this same error.
    According to my experience, if I want to see all the structures and the outputs of an example from internet at the maximum (100%) then it must be compiled (done), and it must not crash (failed).

    191426-crash.jpg

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.