Seeking Help with C2065 Error in C++ Code

Hello everyone,

I'm currently encountering an issue with my C++ code while using the OCCT (Open CASCADE Technology) library. The error I'm receiving is C2065, indicating that "Poles" is an undeclared identifier. Here's the code snippet that's causing the problem:

#include <iostream>
#include <TColgp_Array2OfPnt.hxx>

int main() {
    // Creating a control point matrix
    TColgp_Array2OfPnt Poles(1, 2, 1, 3);
    // Filling the control point matrix

    Poles.SetValue(1, 2, gp_Pnt(1, 2, 3));
    return 0;
}

I'm not sure what's causing this issue and would greatly appreciate any assistance in resolving it.

Thanks in advance for your help!

Dmitrii Pasukhin's picture

Hi, could you share a compiler or linker log? are you sure that you link TKernel.lib (libTKernel.a) and TKMath

Best regards, Dmitrii.

frankrun King's picture

Thank you for your response. I used cmake to build this code. Here is my cmakelists:

cmake_minimum_required(VERSION 3.12.0)

project(mainOcct)

# Set the directory where OpenCASCADE is installed
set(OpenCASCADE_DIR "C:/Users/95439/source/repos/arungoooo112/OCCT/out/install/x64-Debug/cmake")

# Try to find OpenCASCADE package
find_package(OpenCASCADE REQUIRED)

# Check if OpenCASCADE is found
if(OpenCASCADE_FOUND)
    message(STATUS "OpenCASCADE found!")
    message(STATUS "OpenCASCADE_INCLUDE_DIRS: ${OpenCASCADE_INCLUDE_DIRS}")
    message(STATUS "OpenCASCADE_LIBRARIES: ${OpenCASCADE_LIBRARIES}")
else()
    # If OpenCASCADE is not found, print error message and terminate CMake configuration
    message(FATAL_ERROR "OpenCASCADE not found!")
endif()

# Add an executable target
add_executable(mainOcct main.cpp)

# Link OpenCASCADE libraries to the executable
target_link_libraries(mainOcct PRIVATE ${OpenCASCADE_LIBRARIES})

# Include OpenCASCADE header files
target_include_directories(mainOcct PRIVATE ${OpenCASCADE_INCLUDE_DIRS})

message(STATUS "CMake compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "CMake compiler ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMake compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "CMake system name: ${CMAKE_SYSTEM_NAME}")

output:

[main] Configuring project: HelloOcct 
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/95439/Documents/VsCode/HelloOcct -Bc:/Users/95439/Documents/VsCode/HelloOcct/build -G "Visual Studio 17 2022" -T host=x86 -A x64
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
[cmake] CMake Warning (dev) at C:/Users/95439/source/repos/arungoooo112/OCCT/out/install/x64-Debug/cmake/OpenCASCADEConfig.cmake:47:
[cmake]   Syntax Warning in cmake code at column 75
[cmake] 
[cmake]   Argument not separated from preceding token by whitespace.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:9 (find_package)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- OpenCASCADE found!
[cmake] -- OpenCASCADE_INCLUDE_DIRS: 
[cmake] -- OpenCASCADE_LIBRARIES: TKernel;TKMath;TKG2d;TKG3d;TKGeomBase;TKBRep;TKGeomAlgo;TKTopAlgo;TKPrim;TKBO;TKShHealing;TKBool;TKHLR;TKFillet;TKOffset;TKFeat;TKMesh;TKXMesh;TKService;TKV3d;TKOpenGl;TKMeshVS;TKCDF;TKLCAF;TKCAF;TKBinL;TKXmlL;TKBin;TKXml;TKStdL;TKStd;TKTObj;TKBinTObj;TKXmlTObj;TKVCAF;TKDE;TKXSBase;TKDESTEP;TKXCAF;TKDEIGES;TKDESTL;TKDEVRML;TKRWMesh;TKDECascade;TKBinXCAF;TKXmlXCAF;TKDEOBJ;TKDEGLTF;TKDEPLY;TKExpress;TKDraw;TKTopTest;TKOpenGlTest;TKViewerTest;TKXSDRAW;TKDCAF;TKXDEDRAW;TKTObjDRAW;TKQADraw;TKXSDRAWDE;TKXSDRAWGLTF;TKXSDRAWIGES;TKXSDRAWOBJ;TKXSDRAWPLY;TKXSDRAWSTEP;TKXSDRAWSTL;TKXSDRAWVRML
[cmake] -- CMake compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx86/x64/cl.exe
[cmake] -- CMake compiler ID: MSVC
[cmake] -- CMake compiler version: 19.39.33521.0
[cmake] -- CMake system name: Windows
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: C:/Users/95439/Documents/VsCode/HelloOcct/build
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x86 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x86 for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat

it works when i deleted setvalue function.

frankrun King's picture

there are TKernel and TKMath lib

Dmitrii Pasukhin's picture

Thanks, could you share compiler log?

Dmitrii Pasukhin's picture

Additionally I recommend to use CMake like this DE_Wrapper-Sample/src/CoreDE/CMakeLists.txt at main · dpasukhi/DE_Wrapper-Sample (github.com)

It will helps to connect debug and release versions.

Best regards, Dmitrii.

frankrun King's picture

Thank you, problem solved even though I haven't figured out why it occurred.
I simply resaved the 'main.cpp' file as UTF-16 and then saved it again as UTF-8.
Interesting!