Why cannot I use opennurbs in C++ DLL with Visual studio 2019

I wanna use OpenNurbs in C++ and create a DLL. There is no “stdafx.h” in my project, but a header named “pch.h” where, therefore, I added the following lines with the instructions.

#define OPENNURBS_PUBLIC_INSTALL_DIR “DirectoryToOpenNurbs-7x”
#include “…\opennurbs_public.h”

and when I wanted to build up the solution, it failed.
Then secondly, I tried another way. Adding opennurbs_public.dll with the “properties page” which was provided by Microsoft Learn.
But failed neither.
In both approaches, the output console concluded that
Build started…
1>------ Build started: Project: Pyramid, Configuration: Debug x64 ------
1>Bridge.cpp
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(19,13): warning C4251: ‘Pyramid::Pt1’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(20,13): warning C4251: ‘Pyramid::Pt2’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(21,13): warning C4251: ‘Pyramid::Pt3’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(22,13): warning C4251: ‘Pyramid::Pt4’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Bridge.cpp(11,21): error C2526: ‘GetPyramid’: C linkage function cannot return C++ class ‘std::list<ON_Line,std::allocator<ON_Line>>’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(26): message : see declaration of ‘std::list<ON_Line,std::allocator<ON_Line>>’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Bridge.cpp(14,3): error C2562: ‘GetPyramid’: ‘void’ function returning a value
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Bridge.cpp(11): message : see declaration of ‘GetPyramid’
1>Test_1_PointAdd.cpp
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(19,13): warning C4251: ‘Pyramid::Pt1’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(20,13): warning C4251: ‘Pyramid::Pt2’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(21,13): warning C4251: ‘Pyramid::Pt3’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>D:\C++&Java\C++Dll_Learning\Test_Dll_5\OpenNurbs_Test_2\Pyramid\Pyramid\Test_1_PointAdd.h(22,13): warning C4251: ‘Pyramid::Pt4’: class ‘ON_3dPoint’ needs to have dll-interface to be used by clients of class ‘Pyramid’
1>D:\C++&Java\OpenNurbs_2\opennurbs-7.x\opennurbs_texture_mapping.h(32): message : see declaration of ‘ON_3dPoint’
1>Generating Code…
1>Done building project “Pyramid.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How to correct it and why??

Hi @鄭宗偉,

We’re unable to tell what the problem is with just the error messages. You might consider posting your DLL project.

– Dale

Sure.
This is the link to my GitHub repositories.
GitHub - TzhongWei/Pyramid: This is the test program using C++ and OpenNurbs to make a DLL project.
You can access and get the project. Or download it below.
Here is the project.
Pyramid.rar (4.3 KB)
x64.rar (11.5 MB)
Debug.rar (11.4 MB)
Pyramid.rar (570 Bytes)
Excuse me. Due to the uploading size, I could only provide them separately. The first file is the cpp and header files, and the rest are .obj, .log, and .pch which is the largest one. Then, the last one is .sln.
Overall, I just tried to make a pyramid. Thanks.

Hi @鄭宗偉,

Have a look at the attached sample project. Pay close attention to the statements added to .pch.h.

test_opennurbs.vcxproj.zip (3.9 KB)

– Dale

Hi @dale
I’ve tried to add codes in the header “pch.h” as you provided, but it still built up and failed.
Here are the steps I did.

  1. open OpenNurbs and build up x64 debug and release versions separately. However, the debug version was 1 success and 8 failed.
  2. create a new project in 2019 visual studio
  3. open the pch.h and add what you provided in your code.

//Define OPENNURBS_OUT_DIR
#if defined (WIN64)
#if defined (_DEBUG)
#define OPENNURBS_OUTPUT_DIR “D:\C++&Java\opennurbs-7.x\bin\x64\Debug”
#else
#define OPENNURBS_OUTPUT_DIR “D:\C++&Java\opennurbs-7.x\bin\x64\Release”
#endif
#else
#if defined(_DEBUG)
#define OPENNURBS_OUTPUT_DIR “D:\C++&Java\opennurbs-7.x\bin\x64\Debug”
#else
#define OPENNURBS_OUTPUT_DIR “D:\C++&Java\opennurbs-7.x\bin\x64\Release”
#endif
#endif

#include “D:\C++&Java\opennurbs-7.x\opennurbs_public_examples.h”

  1. create a new Pyramid.cpp and add what I want to do in it.
  2. build up x64 release version then failed.

Did I miss any steps? can you provide me with a similar project?

You could have a look at the attached file.
OpenNurbsTest.rar (4.5 KB)

Thank you.

What were the errors? You should be able to build opennurbs_public.sln with no errors.

– Dale

I downloaded Opennurbs from here.

I opened it with opennurbs_public.sln, and set the Configuration Manager into debug mode. Then, just built up in x64 version.
And it said
========== Build: 1 succeeded, 8 failed, 0 up-to-date, 0 skipped ==========

Thanks.

Hi @鄭宗偉,

I believe the C4819 warning have to do with the Region settings on your Windows system. Here is how one user solved the problem.

Sorry I can’t be of more help.

– Dale

3 posts were split to a new topic: OpenNURBS build issue