Error compiling with MinGW64 due to strtok_s

265 views
Skip to first unread message

Eveleen Brooklynn

unread,
Nov 26, 2013, 12:15:04 PM11/26/13
to pt...@googlegroups.com
I generated makefiles with CMake for MinGW64 and I got this error when I try to compile from the command line:

PtexCache.cpp: In member function 'virtual void PtexReaderCache::setSearchPath(const char*):
    PtexCache.cpp:228:40: error: 'strtok_s' was not declared in this scope


You should NOT use strtok_s because is Microsoft-non portable "secure" function.
You should use strtok instead for non-Microsoft compilers as MinGW-g++ :p

thx.

Brent Burley

unread,
Nov 26, 2013, 12:27:56 PM11/26/13
to pt...@googlegroups.com
A multi-threaded application cannot use strtok.

I will remove strtok_r/s and replace with strchr (I'm only use it to divide a colon-delimited searchpath into individual directories).

In the meantime do you have strtok_r?  strok_s is only used on windows; strtok_r is used everywhere else.

Brent Burley

unread,
Nov 26, 2013, 8:22:15 PM11/26/13
to pt...@googlegroups.com
I just pushed a new commit that no longer uses strtok of any kind.

Eveleen Brooklynn

unread,
Nov 27, 2013, 10:03:44 AM11/27/13
to pt...@googlegroups.com
Thanks, Brent.

Now that error is gone ... but I still get these due to more "_s" secure functions too :p

PtexReader.cpp: In member function 'bool PtexReader::open(const char*, Ptex::String&)' :
    PtexReader.cpp:84:55: error 'sprintf_s' was not declared in this cope.

Somebody should find ALL the Microsoft-specific "_s" C CRT funcions and replace them for MinGW64 compatibility, pls :p

Brent Burley

unread,
Nov 27, 2013, 11:25:31 AM11/27/13
to pt...@googlegroups.com
I guess I should have anticipated that.  This won't work very well fixing these one at a time.  I don't have easy access to windows let alone mingw.

Replacing sprintf_s is trivial; I'll do that, but there are other windows-specific replacements to posix functions being used:  _fseeki64/_ftelli64 as replacements for fseeko/ftello, and there are also windows-specific threading primitives to replace pthread.  I'm curious whether Ptex would just work on mingw if it compiled as if for posix.  Can you try this patch:

diff --git a/src/ptex/PtexPlatform.h b/src/ptex/PtexPlatform.h
index af8d851..a7757df 100644
--- a/src/ptex/PtexPlatform.h
+++ b/src/ptex/PtexPlatform.h
@@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 */
 
 // platform-specific includes
-#if defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER)
+#if (defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER)) && !defined(__MINGW64__)
 #ifndef WINDOWS
 #define WINDOWS
 #endif
@@ -58,6 +58,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 
 #else
 
+#ifdef WINDOWS
+#undef WINDOWS
+#endif
+
 // linux/unix/posix
 #include <stdlib.h>
 #include <alloca.h>

Eveleen Brooklynn

unread,
Dec 2, 2013, 8:51:59 AM12/2/13
to pt...@googlegroups.com
Close... :p
I get these errors, probably due to the ned of com std::string::c_str() or const char* cast need:

Scanning dependencies of target Ptex_dynamic
[  4%] Building CXX object ptex/CMakeFiles/Ptex_dynamic.dir/PtexCache.cpp.obj
[  8%] Building CXX object ptex/CMakeFiles/Ptex_dynamic.dir/PtexFilters.cpp.obj
[ 12%] Building CXX object ptex/CMakeFiles/Ptex_dynamic.dir/PtexHalf.cpp.obj
[ 16%] Building CXX object ptex/CMakeFiles/Ptex_dynamic.dir/PtexReader.cpp.obj
D:\kaka\ptex-master\ptex-master\src\ptex\PtexReader.cpp: In member function 'bool PtexReader::open(const char*, Ptex::String&)':
D:\kaka\ptex-master\ptex-master\src\ptex\PtexReader.cpp:86:23: error: no match for 'operator=' in 'error = std::basic_stringstream<_CharT, _Traits, _Alloc>::str() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_stringstream<_CharT, _Traits, _Alloc>::__string_type = std::basic_string<char>]()'
D:\kaka\ptex-master\ptex-master\src\ptex\PtexReader.cpp:86:23: note: candidates are: In file included from D:\kaka\ptex-master\ptex-master\src\ptex\PtexReader.cpp:41:0:
D:\kaka\ptex-master\ptex-master\src\ptex\Ptexture.h:309:18: note: Ptex::String& Ptex::String::operator=(const char*)
D:\kaka\ptex-master\ptex-master\src\ptex\Ptexture.h:309:18: note:   no known conversion for argument 1 from 'std::basic_stringstream<char>::__string_type {aka std::basic_string<char>}' to 'const char*'
D:\kaka\ptex-master\ptex-master\src\ptex\Ptexture.h:310:10: note: Ptex::String& Ptex::String::operator=(const Ptex::String&)
D:\kaka\ptex-master\ptex-master\src\ptex\Ptexture.h:310:10: note:   no known conversion for argument 1 from 'std::basic_stringstream<char>::__string_type {aka std::basic_string<char>}' to 'const Ptex::String&'
mingw32-make[2]: *** [ptex/CMakeFiles/Ptex_dynamic.dir/PtexReader.cpp.obj] Error 1
mingw32-make[1]: *** [ptex/CMakeFiles/Ptex_dynamic.dir/all] Error 2
mingw32-make: *** [all] Error 2

Brent Burley

unread,
Dec 2, 2013, 11:46:33 AM12/2/13
to pt...@googlegroups.com
I fixed the error with Ptex::String.  Can you try again?  Also, if you aren't trying to build Ptex as a Windows DLL you can define PTEX_USE_STDSTRING and use std::string instead of Ptex::String.


--
 
---
You received this message because you are subscribed to the Google Groups "ptex" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ptex+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Eveleen Brooklynn

unread,
Dec 7, 2013, 10:47:46 PM12/7/13
to pt...@googlegroups.com
Works like a charm now !
Thanks, Brent !
Reply all
Reply to author
Forward
0 new messages