MinGW linker problem
Author |
Message |
Cartesian
|
Posted: Mon Sep 13, 2010 12:48 pm Post subject: MinGW linker problem |
|
|
So, a little background, I'm trying to use Flex/Bison to make a compiler for a school project. I've done this before and know how to code the actual files, but I can't get my computer to run it properly.
I have Windows 7, Flex and Bison set up. My problem is the C compiler.
I installed MinGW in C:\MinGW and added C:\MinGW\bin to my path, that seems to work. I need to feed it the line "gcc lex.yy.c -lyl" to link the flex library, but it refuses to work.
My first approach was to use "-LC:\Program Files (x86)\GnuWin32\bin -lyl" so that it would search that location for the library, but I hit the problem that it can't accept spaces as part of the directory. I know there's another way to reach Program files without using spaces, but can't find it online.
Looking into other options, I researched the folders that gcc automatically looks for its linker, "user/local/include" and "user/local/lib" for a linux machine. On windows, I tried copy/pasting the .a files directly into "MinGW\lib" but it doesn't make a difference.
Also, there is a file in my flex include folder titled "unistd.h". When I tried to copy it into MinGW\include, I was told there was already a file there with that name. I chose to not overwrite it since I don't know what it does, but honestly as long as Flex and Bison work I don't care if I wreck everything else in this compiler.
There's also a third alternative, apparently, which is to put a statement in the MinGW bash script that makes the linker check the right place. I have no idea how to do this, I've been using standard command prompt so far.
The program may be compounded somehow by the fact that the files I'm working with are on the D Drive while flex, bison, and MinGW are all on the C drive. If that makes a difference, I can move my work to C.
Can anyone help me with this? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGuardian001
|
Posted: Mon Sep 13, 2010 7:32 pm Post subject: Re: MinGW linker problem |
|
|
Is there a reason you're using "bin" as the library search directory? Library files are typically store in "lib."
Surrounding the path in quotes should make it work,
code: |
gcc myFile.c -L"C:\Program Files(x86)\GnuWin32\lib" -lyl
|
If not, you can add an environment variable. To do this, right click "My Computer" (Computer if you're on vista/7) select "Properties," and go to the advanced tab. Click on the "Environment variables" button, then create a new variable, with the library search path as its value. If you name the variable "Libs" (for example) you can now access it from the command line using
code: |
gcc myFile.c -L%Libs% -lyl
|
|
|
|
|
|
|
Cartesian
|
Posted: Wed Sep 15, 2010 12:44 pm Post subject: Re: MinGW linker problem |
|
|
Ah, you're right it was lib and not bin, but that doesn't solve my problem. Suspecting something else was amiss, I tried this:
hello.cpp
---
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl; cout << "Welcome to C++ Programming" << endl; }
---
and gcc hello.cpp -o hello.exe
it says "undefined reference to std::cout along with many other errors. My gcc isn't linking anything at all. What can I do to fix this? |
|
|
|
|
|
OneOffDriveByPoster
|
Posted: Tue Sep 21, 2010 8:14 pm Post subject: Re: MinGW linker problem |
|
|
Cartesian @ Wed Sep 15, 2010 12:44 pm wrote: and gcc hello.cpp -o hello.exe
it says "undefined reference to std::cout along with many other errors. My gcc isn't linking anything at all. What can I do to fix this? Try using g++ or adding -lstdc++. The gcc invocation will correctly process hello.cpp as a C++ source file, but it will not link to libstdc++. |
|
|
|
|
|
|
|