May be the working directory (where Eclipse launches your program) differs from the directory you use in terminal? Most likely that a call to the standard fopen() function will also result in failure. So, I think your question is not related to OpenCV, try to fopen() a txt-file, and I believe you'll discover that some paths are not configured in your IDE.