Compiler question

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Compiler question

      Hi guys,

      When I compiled (under "release") my project I came across an error:

      error C2349: 'WinMain' cannot be compiled using /clr: 'functions containing both copy constructed arguments and inline asm are not supported'; compile without /clr

      My code does have some "__asm" statements, for example:

      Source Code

      1. inline float FastSquareRoot(float x)
      2. {
      3. __asm
      4. {
      5. fld x;
      6. fsqrt;
      7. fstp x;
      8. }
      9. return x;
      10. }


      When I MSDN'ed I found that by using "#pragma unmanaged" solved my problem. Question is this a 'normal' occurrence? To clarify, should I even be using inline assembly? Also, Will this cause future problems, that is, by using mixed managed and unmanaged code will there potentially be crashes?


      Thanks for the help guys!
      Sabrina
    • As far as I understand, C++ CLI will live happily with unmanaged code. C# or other .NET languages, do not. It takes some interop code to get those to work with unmanaged C++. As it is, you should not be using inline assembly if you are compiling using the /clr switch, which you currently are. I assume that you know how the CLR works and how MS's managed languages work, but you cannot inline assembly into your code, and expect the compiler to generate IL from it. My suggestion, is either a) don't compile with the /clr, b) don't use assembly and just perform a normal square root, or c) take a look at other square root implementations, such as Carmack's Square Root (which returns the inverse square root).

      So to answer the questions in the order asked:
      -Is it a normal occurance? Yes, when you attempt to inline machine specific code with C++ CLI.
      -Will there be crashes/problems with managed/unmanaged code? Depends entirely on how you code. The two can get along just fine and live happily ever after, or you can code in a way that'll cause errors. Generally, though, I'd say shy away from mixing the two unless you know what you're doing. It gets really fun if you mess it up.
      Feel you safe and secure in the protection of your pants . . . but one day, one day there shall be a No Pants Day and that shall be the harbinger of your undoing . . .
    • RE: Compiler question

      I agree with the previous post, i can be major laughs when you screw up managed and native code. Inline assembly language and the .NET support (implied by the /clr option) is a no-no. Are you using Visual C++ express edition? If you are, you may not have a choice but to use /clr.
      One question, are you using assembly language because you need to or because somebody says to? Does your Visual C++ support generating SSE instructions? you may want to play with stuff like that and do a bit of profiling to see what you really need.
      Based on your other posts, nice work on the particle thing by the way, I would avoid .NET. Since you tend use non Microsoft stuff OpenGL/OpenAL I don't see .NET not getting you much.
    • RE: Compiler question

      Thanks guys!

      I should have noted I am using VS 2005 (opps). The function "FastSquareRoot(float x)" is not mine, I got it from a friend. (Like I know assembly...HA!) I was hoping for some fast math functions and thought the function might be a way of getting some speed, (ok, I was told that I could get some speed :)). I don't have a clue as to how the "/clr" switch thingy works, but I am looking into it. (I still can't find where that is in my compiler.) On your recommendations, I will be glad to take out the "__asm" stuff and use the 'proper' functions, also I'm looking into the inverse square root ("Carmack's Square Root") function (totally clueless here). As I mentioned, I'm using VS 2005. and it does have the .NET stuff, but I don't know if you can just turn off that and use the C++ stuff (Make sense?) I have NO idea what "SEE instructions are/is". (for all I know it could be a "Teletubby" thing)
      I will make a point of not mixing code (now that I know what can happen :) )

      You guys are a BIG help! Thanks again!!

      Sabrina

      The post was edited 1 time, last by Sabrina ().

    • RE: Compiler question

      SSE Instructions are CPU instructions that Intel and AMD added to the instruction set for root calculations and other vector math type things. You can enable the compiler to use them be going to C++/Code Generation/Enable Enhanced Instruction Set
      As far as the /clr (Compile with .NET support) goes that is a project setting that is set in the project creation wizard and as near as I can tell can't be changed by easy to use menus and dialog boxes. You have to create a new project without .NET support and add your source files to it or manually edit the /clr out of the project file (.vcproj) itself with an editor like notepad or something. If you're using the Express Edition I don't think you have but to use .NET

      gb
    • RE: Compiler question

      Hi guys,

      My problem is back!! The compiler is yelling about the "/clr" again, but I dont have any "__asm" statments in my project.
      Again, when compiling under "Debug" its ok, but when compiling under "Release" I get the error. How do I go about turning it off/on?? When I click "Project", then "....Properties", it comes up with a dialog box, where do I go from there. I have looked, and looked and can not find where to turn off/on "/clr".

      Theres another BIG (HUGE) problem I'd like to get help for, but I want to see if the "/clr" will fix the problem.

      Thanks guys

      Me
      Frustrated and dazed
    • RE: Compiler question (Internal Compiler Error)

      Setting the option(s) "Enable Intrinsic Functions = No" did not work.

      The "HUGE" problem I mentioned earlier is when I compile and get the following message:

      "...CFont.cpp(86): fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 2708 ) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information"

      I noticed in the compiler message the class "CFont.cpp". I looked and found the following code sniplet:

      void CFont:: Print (..., ...)
      {
      char text[128];

      va_list ap;
      va_start(ap, str); <-- Problem here!!
      vsprintf( text, str.c_str(), ap);
      va_end(ap);

      glEnable(GL_BLEND);
      ...
      }


      "va_start(ap, str); " has a problem when compiling. After commenting a few of the lines out, I re-compile and get the following errors:

      ....error LNK2005: ___crtExitProcess already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __cinit already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __exit already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __cexit already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __c_exit already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __C_Exit_Done already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __C_Termination_Done already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __exitflag already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __wpgmptr already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __pgmptr already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: ___winitenv already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __wenviron already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: ___initenv already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __environ already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: ___wargv already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: ___argv already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: ___argc already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __winminor already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __winmajor already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __winver already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __osver already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __osplatform already defined in LIBCMT.lib(crt0dat.obj)
      ....error LNK2005: __umaskval already defined in LIBCMT.lib(crt0dat.obj)
      ....fatal error LNK1169: one or more multiply defined symbols found


      After spending a few hours trying to make sence of these errors, I came up with a few "suggestion"., and did what the suggestions posted on other sites. Nothing helped. Since I need the ""va_start(ap, str);" statement I went back and uncomment the code and just deal with the "INTERNAL COMPILER ERROR..." compile error.
      I did come across this which is not what I was hoping for.

      I'm at my whitz end guys. Anyone have ideas on how to go about doing a work-around?

      EDIT: I did find this. Does anyone want to translate?


      Sabrina

      The post was edited 2 times, last by Sabrina ().

    • RE: Compiler question (Internal Compiler Error)

      This looks like you've got a confused project file. It appears that the compiler is generating .NET p-code and the linker is trying to assemble a native code (machine code) executable. Are you using Visual C++ Express?
      If you're not using the Express Edition, have you tried creating a new project and adding you sources to it? Be happy to help you try to untie the mess if you can post the project.
    • RE: Compiler question (Internal Compiler Error)

      Hi Garbob and guys,


      This looks like you've got a confused project file...

      hehe, well that makes two of us, me and the project. But just for the record, I'm the one bangning my head on the keyboard. :)

      Since I do not follow in the foot steps of traditional science (i.e. Computer Science), I'm somewhat handicapped by my inexperience and training. I think the best way to solve this is to start performing an autopsy with post-mortem design studies. I've started taking out lots of code and get it to down to a skeleton project and seems to compile fine. I'll start adding my other code to the project until I start getting errors and in the mean time, I'll look for better ways in developing a robust project. From what I've read from other forums, the suggestions where varying, however the approach I've outlined is the best choice for people like my self since it will aid in the educational experience. For a person such as myself, the skills and experience with software development will be beneficial by backtracking and doing redesign work. I think the error boils down to design issues. Proper design skills is essential to a succesful and robust project and ineffective design skills, in my opinion, can lead to errors as I mentioned in previous posts.

      Its comforting that forums like these exits and that armature programming as well as experienced developers, can come and get help from people like MrMike, Kain, Garbob, Rez, and many others, as well as provide help. Its nice to have "mentors". Thanks allot guys! (Okay, that sounds alot like my Academy Award speech...."Men in Kilts")

      Me.