본문으로 바로가기

opennurbs for mingw

category Devlogs 2024. 3. 8. 12:42

Rhino사의 nurbs 취급 라이브러리인 opennurbs 를 mingw로 컴파일 하기 위해서 약간의 수정이 필요한데..
https://www.rhino3d.com/kr/opennurbs/

본 소스는 현재 최신버전으로 아래에서 받았음.
https://github.com/mcneel/opennurbs/archive/refs/tags/v7.6.21127.19001.tar.gz

기본으로 opennurbs 는 윈도우즈상에서의 컴파일은 VC++ 7.0 & 9.0 Community 버전만 지원함.
난 MinGW 를 주로 쓰기 때문에 직접 opennurbs 코드를 수정해서 컴파일 및 테스트까지 성공한 diff 를 올려둠

opennurbs-7.6.21127.19001.diff_.zip
0.00MB


그리고 컴파일을 위해서는 MinGW용 uuid가 필요함. (https://github.com/h0tw1r3/libuuid-mingw)

사용된 MinGW g++ 버전은 아래와 같음

[MIN@DESKTOP-RSH0QT3 build]$ g++ --version
g++.exe (Rev2, Built by MSYS2 project) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


암튼 아래는 diff...

diff -ur opennurbs-7.6.21127.19001/makefile opennurbs-7.6.21127.19001.mingw/makefile
--- opennurbs-7.6.21127.19001/makefile  2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/makefile    2021-08-07 01:25:29.550215500 +0900
@@ -15,7 +15,7 @@
 # asks too many questions, then uncomment the next line.
 # RM = /bin/rm -f
  
-AR = ar qvl
+AR = ar r
  
 # If your system doesn't use ranlib, uncomment the "echo" define.
 RANLIB = ranlib
@@ -27,11 +27,11 @@
  
 # Choose one of the following definitions for GCC_OPTIMIZER_FLAGS
 # unoptimized debug build
-ON_GNU_OPTIMIZER_FLAGS = -g
+#ON_GNU_OPTIMIZER_FLAGS = -g
 # optimized release build
-#ON_GNU_OPTIMIZER_FLAGS = -O
+ON_GNU_OPTIMIZER_FLAGS = -O
  
-ON_GNU_WARNING_FLAGS = -Wall \
+#ON_GNU_WARNING_FLAGS = -Wall \
    -Wno-overloaded-virtual \
    -Wno-switch \
    -Wno-unknown-pragmas \
@@ -277,6 +277,7 @@
    opennurbs_fsp.cpp \
    opennurbs_function_list.cpp \
    opennurbs_geometry.cpp \
+   opennurbs_gl.cpp \
    opennurbs_glyph_outline.cpp \
    opennurbs_group.cpp \
    opennurbs_hash_table.cpp \
@@ -454,6 +455,7 @@
    opennurbs_fsp.o \
    opennurbs_function_list.o \
    opennurbs_geometry.o \
+   opennurbs_gl.o \
    opennurbs_glyph_outline.o \
    opennurbs_group.o \
    opennurbs_hash_table.o \
@@ -843,22 +845,22 @@
 ## $(RANLIB) $@
  
 example_read/example_read : example_read/example_read.o example_userdata/example_ud.o $(OPENNURBS_LIB_FILE)
-   $(LINK) $(LINKFLAGS) example_read/example_read.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
+   $(LINK) $(LINKFLAGS) example_read/example_read.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -luuid_mingw -lrpcrt4 -o $@
  
 example_write/example_write : example_write/example_write.o example_userdata/example_ud.o $(OPENNURBS_LIB_FILE)
-   $(LINK) $(LINKFLAGS) example_write/example_write.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
+   $(LINK) $(LINKFLAGS) example_write/example_write.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -luuid_mingw -lrpcrt4 -o $@
  
 example_test/example_test : example_test/example_test.o $(OPENNURBS_LIB_FILE)
-   $(LINK) $(LINKFLAGS) example_test/example_test.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
+   $(LINK) $(LINKFLAGS) example_test/example_test.o -L. -l$(OPENNURBS_LIB_NAME) -lm -luuid_mingw -lrpcrt4 -o $@
  
 example_convert/example_convert : example_convert/example_convert.o example_userdata/example_ud.o $(OPENNURBS_LIB_FILE)
-   $(LINK) $(LINKFLAGS) example_convert/example_convert.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
+   $(LINK) $(LINKFLAGS) example_convert/example_convert.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -luuid_mingw -lrpcrt4 -o $@
  
 example_brep/example_brep : example_brep/example_brep.o $(OPENNURBS_LIB_FILE)
-   $(LINK) $(LINKFLAGS) example_brep/example_brep.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
+   $(LINK) $(LINKFLAGS) example_brep/example_brep.o -L. -l$(OPENNURBS_LIB_NAME) -lm -luuid_mingw -lrpcrt4 -o $@
  
 example_userdata/example_userdata : example_userdata/example_userdata.o $(OPENNURBS_LIB_FILE)
-   $(LINK) $(LINKFLAGS) example_userdata/example_userdata.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
+   $(LINK) $(LINKFLAGS) example_userdata/example_userdata.o -L. -l$(OPENNURBS_LIB_NAME) -lm -luuid_mingw -lrpcrt4 -o $@
  
 clean :
    -$(RM) $(OPENNURBS_LIB_FILE)
Only in opennurbs-7.6.21127.19001.mingw: opennurbs-7.6.21127.19001.diff
diff -ur opennurbs-7.6.21127.19001/opennurbs_defines.cpp opennurbs-7.6.21127.19001.mingw/opennurbs_defines.cpp
--- opennurbs-7.6.21127.19001/opennurbs_defines.cpp 2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_defines.cpp   2021-08-06 11:53:33.991438200 +0900
@@ -503,7 +503,11 @@
   //fcloseall is not supported on OS X
   return EOF;
 #elif defined(ON_COMPILER_GNU)
+#ifdef __MINGW32__
+  return _fcloseall(); // ANSI C name
+#else
   fcloseall();
+#endif
 #else
   // I can't find an fcloseall() or _fcloseall() in
   // gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
diff -ur opennurbs-7.6.21127.19001/opennurbs_file_utilities.cpp opennurbs-7.6.21127.19001.mingw/opennurbs_file_utilities.cpp
--- opennurbs-7.6.21127.19001/opennurbs_file_utilities.cpp  2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_file_utilities.cpp    2021-08-06 11:34:33.475516900 +0900
@@ -2261,7 +2261,11 @@
   ON_String m_utf8_file_name_filter;
   DIR* m_dir = nullptr;
   struct dirent m_dirent;
+#ifdef __MINGW32__
+  char m_dirent_name_buffer[FILENAME_MAX+1]; // < this field provide storage for m_dirent.d_name[]
+#else
   char m_dirent_name_buffer[NAME_MAX+1]; // < this field provide storage for m_dirent.d_name[]
+#endif
  
   // information about the current file
   wchar_t m_current_name[1024];
@@ -2521,6 +2525,7 @@
   {
     current_file_attributes = 0;
     struct dirent* dp = 0;
+#ifndef __MINGW32__
     int readdir_errno = readdir_r(m_impl->m_dir, &m_impl->m_dirent, &dp);
     if ( 0 !=  readdir_errno )
       break;
@@ -2528,6 +2533,7 @@
       break;
     if ( 0 == m_impl->m_dirent.d_name[0] )
       break;
+#endif
  
     if ( IsDotOrDotDotDir(m_impl->m_dirent.d_name) )
       continue;
diff -ur opennurbs-7.6.21127.19001/opennurbs_gl.cpp opennurbs-7.6.21127.19001.mingw/opennurbs_gl.cpp
--- opennurbs-7.6.21127.19001/opennurbs_gl.cpp  2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_gl.cpp    2021-08-07 01:28:05.000549100 +0900
@@ -16,6 +16,7 @@
  
 #include "opennurbs.h"
 #include "opennurbs_gl.h" // ON_GL() function declarations
+#include "opennurbs_material.h" // ON_GL() function declarations
  
 void ON_GL( const int order,     // ON_NurbsCurve order
               const int cv_count,  // ON_NurbsCurve cv count
@@ -600,7 +601,7 @@
     ON_GL( pMat->Diffuse(), alpha, diffuse );
     ON_GL( pMat->Specular(), alpha, specular );
     ON_GL( pMat->Emission(), alpha, emission );
-    GLint shine = (GLint)(128.0*(pMat->Shine() / ON_Material::MaxShine()));
+    GLint shine = (GLint)(128.0*(pMat->Shine() / ON_Material::MaxShine));
     if ( shine == 0 ) {
       specular[0]=specular[1]=specular[2]=(GLfloat)0.0;
     }
diff -ur opennurbs-7.6.21127.19001/opennurbs_lock.h opennurbs-7.6.21127.19001.mingw/opennurbs_lock.h
--- opennurbs-7.6.21127.19001/opennurbs_lock.h  2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_lock.h    2021-08-06 11:20:52.843563800 +0900
@@ -115,8 +115,12 @@
 #if defined(ON_COMPILER_CLANG)
     std::atomic<int> m_lock_value;
 #else
+#ifdef __MINGW32__
+  std::atomic<int> m_lock_value = {ON_Lock::UnlockedValue};
+#else
   std::atomic<int> m_lock_value = ON_Lock::UnlockedValue;
 #endif
+#endif
 #pragma ON_PRAGMA_WARNING_POP
 };
  
diff -ur opennurbs-7.6.21127.19001/opennurbs_public_version.h opennurbs-7.6.21127.19001.mingw/opennurbs_public_version.h
--- opennurbs-7.6.21127.19001/opennurbs_public_version.h    2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_public_version.h  2021-08-06 11:41:02.424272500 +0900
@@ -73,9 +73,11 @@
 // At this time, verrsrc.h does not have protection against multiple includes.
 // Testing for VS_FF_PRERELEASE seems to prevent double incudes and the
 // redef errors it generates.
+#ifndef __MINGW32__
 #include "verrsrc.h"
 #endif
 #endif
+#endif
  
 #define RHINO_FILE_FLAGS_MASK VS_FF_PRERELEASE
  
diff -ur opennurbs-7.6.21127.19001/opennurbs_statics.cpp opennurbs-7.6.21127.19001.mingw/opennurbs_statics.cpp
--- opennurbs-7.6.21127.19001/opennurbs_statics.cpp 2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_statics.cpp   2021-08-06 11:39:25.652762400 +0900
@@ -497,7 +497,11 @@
 const ON_SHA1_Hash ON_SHA1_Hash::EmptyContentHash = ON_SHA1_Hash_EmptyContentHash();
 const ON_SHA1_Hash ON_SHA1_Hash::ZeroDigest ON_CLANG_CONSTRUCTOR_BUG_INIT(ON_SHA1_Hash);
  
+#ifdef __MINGW32__
+const ONX_ModelTest ONX_ModelTest::Unset {ON_CLANG_CONSTRUCTOR_BUG_INIT(ONX_ModelTest)};
+#else
 const ONX_ModelTest ONX_ModelTest::Unset ON_CLANG_CONSTRUCTOR_BUG_INIT(ONX_ModelTest);
+#endif
  
 // Works with Microsoft's CL, fails for Apple's CLang
 ////   const struct ON_UnicodeErrorParameters ON_UnicodeErrorParameters::MaskErrors   = { 0, 0xFFFFFFFF, ON_UnicodeCodePoint::ON_ReplacementCharacter };
@@ -713,7 +717,11 @@
 const ON_LengthValue ON_LengthValue::Unset ON_CLANG_CONSTRUCTOR_BUG_INIT(ON_LengthValue);
 const ON_LengthValue ON_LengthValue::Zero = ON_LengthValue::Create(0.0, ON::LengthUnitSystem::None, 0, ON_LengthValue::StringFormat::CleanDecimal);
  
+#ifdef __MINGW32__
+const ON_AngleValue ON_AngleValue::Unset {ON_CLANG_CONSTRUCTOR_BUG_INIT(ON_AngleValue)};
+#else
 const ON_AngleValue ON_AngleValue::Unset ON_CLANG_CONSTRUCTOR_BUG_INIT(ON_AngleValue);
+#endif
 const ON_AngleValue ON_AngleValue::Zero = ON_AngleValue::Create(0.0, ON::AngleUnitSystem::None, 0, ON_AngleValue::StringFormat::CleanDecimal );
  
 const ON_ScaleValue ON_ScaleValue::Unset ON_CLANG_CONSTRUCTOR_BUG_INIT(ON_ScaleValue);
diff -ur opennurbs-7.6.21127.19001/opennurbs_system.h opennurbs-7.6.21127.19001.mingw/opennurbs_system.h
--- opennurbs-7.6.21127.19001/opennurbs_system.h    2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_system.h  2021-08-06 11:28:05.427679200 +0900
@@ -22,6 +22,10 @@
 ////////////////////////////////////////////////////////////////
 */
  
+#ifdef __MINGW32__
+#define ON_NO_WINDOWS
+#endif
+
 #if !defined(OPENNURBS_SYSTEM_INC_)
 #define OPENNURBS_SYSTEM_INC_
  
diff -ur opennurbs-7.6.21127.19001/opennurbs_system_runtime.h opennurbs-7.6.21127.19001.mingw/opennurbs_system_runtime.h
--- opennurbs-7.6.21127.19001/opennurbs_system_runtime.h    2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_system_runtime.h  2021-08-06 11:28:45.137120900 +0900
@@ -61,6 +61,11 @@
 #endif
  
 #endif
+
+#ifdef __MINGW32__
+#undef ON_RUNTIME_WIN
+#define ON_RUNTIME_LINUX
+#endif
 /*
 //
 // END - ON_RUNTIME_APPLE / ON_RUNTIME_WIN / ON_RUNTIME_ANDROID defines
diff -ur opennurbs-7.6.21127.19001/opennurbs_uuid.h opennurbs-7.6.21127.19001.mingw/opennurbs_uuid.h
--- opennurbs-7.6.21127.19001/opennurbs_uuid.h  2021-05-24 10:38:07.000000000 +0900
+++ opennurbs-7.6.21127.19001.mingw/opennurbs_uuid.h    2021-08-06 11:26:23.434502300 +0900
@@ -24,9 +24,9 @@
   // opennurbs.dll builds.
   #define ON_UUID_DEFINED
   // ON_UUID is a 16 byte universally unique identifier
-  #if defined(UUID_DEFINED)
+  #if defined(UUID_DEFINED) && !defined(__MINGW32__)
   typedef UUID ON_UUID;
-  #elif defined(GUID_DEFINED)
+  #elif defined(GUID_DEFINED) && !defined(__MINGW32__)
   typedef GUID ON_UUID;
   #else
   typedef struct ON_UUID_struct

 


Korea Tcl/Tk Community
블로그 이미지 ihmin 님의 블로그
VISITOR 오늘 / 전체