Compiling on Cygwin, but not on Dev-C++... Why?

This is a discussion on Compiling on Cygwin, but not on Dev-C++... Why? within the C++ Programming forums, part of the General Programming Boards category; Code: /* Obtencao do conjunto potencia de um vector de inteiros. Autor: Miguel Martins <Mr_Miguel40@hotmail.com> <marm@student.dei.uc.pt> */ #include <iostream> #include ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Location
    Coimbra, Portugal
    Posts
    64

    Compiling on Cygwin, but not on Dev-C++... Why?

    Code:
    /*
    Obtencao do conjunto potencia de um vector de inteiros.
    Autor: Miguel Martins <Mr_Miguel40@hotmail.com> <marm@student.dei.uc.pt>
    */
    #include <iostream>
    #include <vector>
    #include <cmath>
    using namespace std;
    
    vector< vector<int> > getPowerSet(vector<int> s);
    string toBinaryString(int i);
    string reverseString(string s);
    vector<int> mergeVectorAndString(vector<int> v,string s);
    
    int main() {
        vector<int> v;
        v.push_back(1);
        v.push_back(2);
        v.push_back(3);
        vector< vector<int> > resultado = getPowerSet(v);
        for (unsigned int i=0;i<resultado.size();i++) {
            cout << "{";
            for (unsigned int j=0;j<resultado[i].size();j++)
                cout << resultado[i][j] << " ";
            cout << "}" << endl;
        }
        
        string end;
        cin >> end;
        return 0;
    }
    
    vector< vector<int> > getPowerSet(vector<int> v) {
        vector< vector<int> > power_set;
        int number_of_elements = (int)pow((double)2,(double)v.size());
        for (int i=0;i<number_of_elements;i++) {
            string s = toBinaryString(i);
            power_set.push_back(mergeVectorAndString(v,s));
        }
        return power_set;
    }
    
    string toBinaryString(int i) {   
        string ret;
        while(1) { 
            int foo = i % 2;
            ret += (foo + '0');
            i /= 2;
            if (i==0) break;
        }
        ret = reverseString(ret);
        return ret;
    }
    
    string reverseString(string s) {
        int n = s.size();
        for (int i=0;i<n/2;i++) {
            char foo = s[i];
            s[i] = s[n-i-1];
            s[n-i-1] = foo;
        }
        return s; 
    }
    
    vector<int> mergeVectorAndString(vector<int> v,string s) {
        vector<int> ret;
        string s1;
        for (unsigned int i=0;i<(v.size()-s.size());i++) s1 += "0";
        s1 += s;
        for (unsigned int i=0;i<s1.size();i++) if (s1[i]=='1') ret.push_back(v[i]);
        return ret;
    }
    Apparently, this compiles correctly on Cygwin, using g++, but not on Dev-C++.
    Dev-C++ gives me the following error:

    [Linker error] undefined reference to `__cpu_features_init'

    Can you guys successfully compile this under Dev-C++? Do you have to make any changes in order to accomplish that? Please let me know.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Are you compiling the code in the same place, using two different compilers?

    If so, try a "clean" build to make sure none of the previous compilers' output is left lying around.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Location
    Coimbra, Portugal
    Posts
    64
    I'm sorry, I didn't quite understand what you mean... "Compiling code in the same place"? As in... "Compiling under the same directory"? If so, it doesn't matter, because even if I move my source file into an empty directory, it won't compile with Dev-C++.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    No problem here compiling with dev-c++ (4.9.9.2)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Location
    Coimbra, Portugal
    Posts
    64
    Unbelievable! Now Dev-C++ won't even compile the "Hello World" program! What is the meaning of this? Where did that stupid linker error come from? Oh well, I guess I'm off to reinstall Dev-C++. Thanks for trying to help.

  6. #6
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    My best guess is that both compilers trying to link to the same libraries.
    You propably got the library path mixed up.
    Kurt

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Something similar happened to me with Dev-C++. I just instaslled Code::Blocks.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    Registered User
    Join Date
    Nov 2006
    Location
    Coimbra, Portugal
    Posts
    64
    I took manutd's advice, but it was still giving me that error... You're not gonna believe what caused it... I had another installation of MinGW on drive D:! Once I removed it, things worked perfectly. God, I feel so silly.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    23

    thanks guys

    i ran into this exact same problem if it wasn't for this forum i would have been stuck

  10. #10
    Registered User
    Join Date
    Jan 2009
    Posts
    1

    Thumbs up heyy thanksss

    Mee too!! I have this problem aproximatly a year ago and its stressing. So Thanks Mr_Miguel because is a simple program like WinGW that don't let the devc++ copile perfectly and i simply unistall Wingw and dev copile without a ploblem!!! THANKSSSSSSSSS

  11. #11
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    You have 2 copies of MinGW installed.

    I felt like smacking my head against the nearest wall when I figured it out after hours of Googling.

    *edit*
    Ah okay, I see it's already solved.
    */edit*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bloodshed Dev Stops Compiling
    By bengreenwood in forum C++ Programming
    Replies: 4
    Last Post: 11-11-2007, 02:25 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Problems with compiling code in cygwin
    By firyace in forum C++ Programming
    Replies: 4
    Last Post: 06-01-2007, 08:16 AM
  4. Cygwin Server
    By osal in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-07-2005, 11:58 AM
  5. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 12:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21