HELP me with error std::string::npos!

395 views
Skip to first unread message

wangdo...@gmail.com

unread,
Dec 4, 2013, 3:55:39 AM12/4/13
to scl...@googlegroups.com
I built SC.sln with vs2010 but there were many link errors with std::string::npos. Here is one of them. Could anyone help me to fix it? Thanks a lot!!

5>p21read.obj : error LNK2001: unresolved external symbol "public: static unsigned int const std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::npos" (?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB)
5>D:\1-work\stepcode\build\bin\p21read_sdai_10303-219-AIM-long.exe : fatal error LNK1120: 1 unresolved externals

Mark

unread,
Dec 4, 2013, 8:28:32 AM12/4/13
to scl...@googlegroups.com

Hi

I do not know why you are having trouble. Others have built SC with vs08 and vs10 and haven't had that issue.

Have you made any changes to the code? If so, try to build using the original files and see if the problem persists.

It looks like you sent 3 almost identical messages to the list. I didn't realize how similar they were until after I'd approved 2 of them.

Messages from new list members are delayed until I look at them to discourage spam, and that's why your first message didn't go through immediately.

Regards
Mark

--
You received this message because you are subscribed to the Google Groups "STEPcode - Developers Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scl-dev+u...@googlegroups.com.
To post to this group, send email to scl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scl-dev/3f06eee8-175e-4754-a4cc-81d3644bc2a8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

wangdo...@gmail.com

unread,
Dec 5, 2013, 1:39:19 AM12/5/13
to scl...@googlegroups.com
Thank you for the reply, Mark!
I did make some changes to the original code. Because there were some errors. Here are my detailed steps, please help me figure out where is the problem. Thanks for your kindness!

step 1: Follow the instructions in "Getting Stated". 1) download code in git; 2) cmake .. -DSC_BUILD_SCHEMAS=ALL; 3) open SC.sln in vs2010 and build "ALL_BUILD".
step 2: some projects "Build Failed". So I changed some lines to make them work.
           1)
           error info: index_attribute undefined type.
           solution:  in "classes_python.c" function ENTITYincode_print(), remove if(false){}, then move lines before ln:index_attribute=0 in front of "{"
           2)
           error info:  'EXPRlength' : redefinition; different linkage.
           solution: in "pretty_expr.h", comment line: int EXPRlength( Expression e );
           3)
           error info: unresolved external symbol __imp__SUBTYPEto_string referenced in function _ENTITYincode_print
           solution: in "pretty_subtype.h", comment line: char * SUBTYPEto_string( Expression e ); in "pretty_subtype.c", add: #include "exppp.h".
step 3: rebuild all, then "std::basic_string" LNK2001 errors come out again :(

wangdo...@gmail.com

unread,
Dec 5, 2013, 1:39:53 AM12/5/13
to scl...@googlegroups.com
Thank you for the reply, Mark!
I did make some changes to the original code. Because there were some errors. Here are my detailed steps, please help me figure out where is the problem. Thanks for your kindness!

step 1: Follow the instructions in "Getting Stated". 1) download code in git; 2) cmake .. -DSC_BUILD_SCHEMAS=ALL; 3) open SC.sln in vs2010 and build "ALL_BUILD".
step 2: some projects "Build Failed". So I changed some lines to make them work.
           1)
           error info: index_attribute undefined type.
           solution:  in "classes_python.c" function ENTITYincode_print(), remove if(false){}, then move lines before ln:index_attribute=0 in front of "{"
           2)
           error info:  'EXPRlength' : redefinition; different linkage.
           solution: in "pretty_expr.h", comment line: int EXPRlength( Expression e );
           3)
           error info: unresolved external symbol __imp__SUBTYPEto_string referenced in function _ENTITYincode_print
           solution: in "pretty_subtype.h", comment line: char * SUBTYPEto_string( Expression e ); in "pretty_subtype.c", add: #include "exppp.h".
step 3: rebuild all, then "std::basic_string" LNK2001 errors come out again :(




On Wednesday, December 4, 2013 9:28:32 PM UTC+8, mark wrote:

Davy Wouters

unread,
Dec 5, 2013, 1:48:54 PM12/5/13
to scl...@googlegroups.com
Hi,
 
It has been quite a while since I build the latest version from git master in vs2010.
It is the git master you are trying to build, right?
 
I’ll give the build another try and post my results, solutions as soon as I got them...
 
Regards,
Dave

Mark

unread,
Dec 5, 2013, 2:34:00 PM12/5/13
to scl...@googlegroups.com

Davy,

Thank you for taking a look.

Wangdong,

One of the errors was discussed at https://github.com/stepcode/stepcode/issues/273 . I meant to work on it, but have not had a chance to do so.

Regards
Mark

dave

unread,
Dec 5, 2013, 4:20:12 PM12/5/13
to scl...@googlegroups.com
Hi Wangdong, Mark, 

I can report I have the same issues that you describe, also with the linker problem of std::basic_string::npos.
I think it can be resolved somehow using a technique described in this article: http://support.microsoft.com/default.aspx?scid=KB;EN-US;168958
But I'm not sure where to put the export code for std::basic_string...
I tried some obvious places which do not work, because then we get multiple definitions of the same type errors.

If someone has more ideas or other insights after reading the article, please feel free to join the discussion ;)
In the mean time I will try some more combinations and see if I can come up with a solution...

Regards,
Dave

dave

unread,
Dec 5, 2013, 4:53:59 PM12/5/13
to scl...@googlegroups.com
@Mark,

It seems that this commit (https://github.com/stepcode/stepcode/commit/b5af88b26809037348e609514e48d98248524268) introduces the linker problem in MSVC 2010.
After some more looking through the code I remembered I fixed a similar issue in the past with error descriptors where we needed to prevent std::string instances to be exported
for msvc2010 because ::npos member did not get imported by a .exe.
This was logged as a bug in msvc2010 first, but then closed as 'by design', meaning just don't export stl stuff :(
msvc 2005 and 2008 did not have this problem, I don't know about newer versions than 2010.
Did this commit have more reasons other than fixing warnings?

@Wangdong,

Could you try with commenting lines 41 to 44 (as below) in sc_benchmark.h?

#ifdef _WIN32
  template class SC_BASE_EXPORT std::allocator<char>;
  template class SC_BASE_EXPORT std::basic_string<char, std::char_traits<char>, std::allocator<char> >;
#endif

Regards,
Dave







Op donderdag 5 december 2013 22:20:12 UTC+1 schreef dave:

Mark

unread,
Dec 5, 2013, 5:06:10 PM12/5/13
to scl...@googlegroups.com
On Thu, Dec 5, 2013 at 4:53 PM, dave <davy.w...@gmail.com> wrote:
@Mark,

It seems that this commit (https://github.com/stepcode/stepcode/commit/b5af88b26809037348e609514e48d98248524268) introduces the linker problem in MSVC 2010.
After some more looking through the code I remembered I fixed a similar issue in the past with error descriptors where we needed to prevent std::string instances to be exported
for msvc2010 because ::npos member did not get imported by a .exe.
This was logged as a bug in msvc2010 first, but then closed as 'by design', meaning just don't export stl stuff :(
msvc 2005 and 2008 did not have this problem, I don't know about newer versions than 2010.
Did this commit have more reasons other than fixing warnings?

I thought I ran into compiler errors without that change, but I must be mistaken since you don't have trouble and since the commit message  begs to differ.

There is a workaround there that might help:

#if _MSC_VER >= 1600
const std::basic_string<char>::size_type std::basic_string<char>::npos = (std::basic_string<char>::size_type) -1;
#endif

Regards
Mark

Regards,
Dave




wangdo...@gmail.com

unread,
Dec 6, 2013, 2:16:02 AM12/6/13
to scl...@googlegroups.com
Sorry for being late~ I'm in different time zone :)
I changed sc_benchmark.h as @Dave said. All works fine now!  Thanks for your patience and time! And for this great project!

Best regards,
Wang Dong
Reply all
Reply to author
Forward
0 new messages