3

I am using Visual Studio 2015.

Currently I am working on a wrapper for log4cxx so that any other logging library can be used later down the line.

I am using DOMConfigurator to parse an XML configuration file. Basically my function wraps DOMConfigurator::configure().

I pass it a literal string, which is the name of my configuration file, in this case, "TESTXML.xml", however, I receive the message on my console that:

log4cxx: Could not open file [TESTXML.xml].

I have also tried passing it a string variable, to no avail.

Why can't I open the file? I have added my file under "Source Files" and modified the properties:

  • Content: Yes
  • Excluded From Build: No

Perhaps there is a setting in MSVS2015 I am forgetting to configure?

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Doug
  • 41
  • 4
  • Is that file placed in your process working directory? Did you try a full pathname? – user0042 Aug 16 '17 at 17:15
  • I have tried a full pathname, it results in the same error. – Doug Aug 16 '17 at 17:17
  • 2
    Did you escape the path separators correctly with the full pathname? Your example isn't sufficient. What's fact for sure is, that your process won't run by default in the same directory (working directory) where your sources are placed. Provide a [MCVE] in your question please. – user0042 Aug 16 '17 at 17:21
  • 1
    You were correct. I did not have the file in my working directory! Thanks! – Doug Aug 16 '17 at 17:22

1 Answers1

1

Perhaps there is a setting in MSVS2015 I am forgetting to configure?

No, it doesn't have to do with the configuration of that file (which should be excluded from the build BTW).

With the information given in your question, the most probable reason that opening the configuration XML file fails is that it's not located in the same directory where your process is started.

Visual Studio will run the executable in the same directory as it was created by default (i.e. $(ProjectDir)/<target>/Debug or $(ProjectDir)/<target>/Release).

You can modify the process working directory in the project properties debug settings, or open a cmd window, change to the desired working directory and start your executable manually.

Another option is to set the full path filename for the configuration file (e.g. "c:\user\xyz\MySolution\MyProject\TESTXML.xml"). Remember that for C++ string literals, you need to escape the backslash characters (\ ==> \\), unless you are using a raw string literal.

user0042
  • 7,917
  • 3
  • 24
  • 39