Sign in to follow this  
obi-wan shinobi

VC++ link errors and antivirus issue

Recommended Posts

So, in the process of trying to build a level parser for my SFML project, I try some file loading code using a FILE object and an istream object, but neither seemed to want to read a file, though at least the FILE object verified that the file was present and opened. The strange thing is that elsewhere in my code, I had another FILE object that was writing debug messages to a text file and this had no problems opening the file or writing to it.

The problem is that after crashing a few times, my application was targeted as malware by AVG antivirus and placed in the virus vault. I had to restart my system in order to scan it, after which no viruses were found. The message from AVG itself listed "conhost.exe" as a system process that was connected to my game executable in the Release folder of VC++ 2008.

Oh, and no matter how many times I try, the code will not create an executable in the Release configuration anymore, though the Debug configuration will (as long as I don't mind using the Debug dlls).

1>LINK : fatal error LNK1104: cannot open file 'C:\Users\user_1\Documents\Visual Studio 2008\Projects\sfml_cpp_1\Release\sfml_cpp_1.exe'

That's the error message I've been getting ever since my level parsing code has had a problem.
FILE *test;
char *text;
test = fopen("debugtext.txt", "r");
fgets(text, 35, test);
int l = strlen(text);
// insert null terminator over the newline
text[l-2] = 0;
cout << "File output: " << text << endl << "Output length: " << l << endl;

This is the code similar to the code that crashed my program and was assumed to be malware, except it had no problem working when I tested it.

Does anyone have any good idea on why this happened or has this happened to others?

Share this post


Link to post
Share on other sites
fastcall22    10838
Quote:
Original post by obi-wan shinobi

FILE *test;
char *text;
test = fopen("debugtext.txt", "r");
fgets(text, 35, test);
int l = strlen(text);
// insert null terminator over the newline
text[l-2] = 0;
cout << "File output: " << text << endl << "Output length: " << l << endl;



You're using C++; use fstream, string, and getline. They'll make your life a whole lot easier:


ifstream fs( "debugtext.txt" );
string line;
getline( fs, line ); // Look! We didn't even need to know the length of the line before hand!

cout << "File output: " << line << endl << "Output length" << line.length() << endl;




That aside, fgets requires the str parameter to point to a character array. In your code, text does not point to any such thing, and fgets happily writes over who-knows-what with the contents of your file.

Quote:

Oh, and no matter how many times I try, the code will not create an executable in the Release configuration anymore, though the Debug configuration will (as long as I don't mind using the Debug dlls).


Did you try rebuilding your project? Have you tried migrating to a new project?

Quote:

... though at least the FILE object verified that the file was present and opened


Wait, what?

[Edited by - _fastcall on November 12, 2010 2:18:36 AM]

Share this post


Link to post
Share on other sites
Migrating the source files to another project worked, but rebuilding the old project in VC++ still give the same linker error. Cleaning the project and building gives the error too.

About fstream and c++, I do know how to use it and would have preferred to, but for whatever reason, I had trouble getting it to work in my project so far. What I meant by "though at least the FILE object verified that the file was present and opened" was that code such as

if(file != NULL)
cout << "Success" << endl;
else
cout << "Failure" << endl;

will print "Success" after a call to fopen(file, "r"), even though trying to read even the first line would cause a crash, and writing to a file opened with "w" presented no problems whatsoever. I'll try fstream again in this new project and probably post whatever code and errors I get from it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this