0

Firstly, I've been working on this for days now and I've tried all possible fixes (went to 10th Google search page searching for a fix) but I can't get it to work.

I'm porting Unix app (G++/Bison/Flex) to Windows (MSVC/WinBison/WinFlex). I'm using CMake as a build system and the idea is to build the project from VS CMD and get VS project ready for modification. The project is meant to work on both platforms so all the modifications should be done in CMakeLists.txt so that I don't have to write special instructions done in VS.

Problematic line in preprocessor.cc is

State current(task->CPFs);

while the method State(std::vector<ConditionalProbabilityFunction*> const& cpfs) is declared in states.h with following code:

struct State { State(std::vector<ConditionalProbabilityFunction*> const& cpfs); State(State const& other) : state(other.state) {} State(int stateSize) : state(stateSize, 0.0) {}

and implemented in states.cc:

State::State(vector<ConditionalProbabilityFunction*> const& cpfs) { for (unsigned int i = 0; i < cpfs.size(); ++i) { state.push_back(cpfs[i]->getInitialValue()); } }

states.h is included in states.cc and rddl.h (which is included in preprocessor.cc) and class States is forward declared in preprocessor.h (which is included in preprocessor.cc).

The errors I'm getting are

[ 36%] Linking CXX executable rddl-parser.exe preprocessor.cc.obj : error LNK2019: unresolved external symbol "public: __thiscall State::State(class std::vector<struct ConditionalProbabilityFunction *,class std::allocator<struct ConditionalProbabilityFunction *> > const &)" (??0State@@QAE@ABV?$vector@PAUConditionalProbabilityFunction@@V?$allocator@PAUConditionalProbabilityFunction@@@std@@@std@@@Z) referenced in function "private: void __thiscall Preprocessor::prepareActions(void)" (?prepareActions@Preprocessor@@AAEXXZ) rddl.cc.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall LogicalExpression::evaluate(double &,struct State const &,class ActionState const &)const " (?evaluate@LogicalExpression@@UBEXAANABUState@@ABVActionState@@@Z)

Linking, when build on Unix, works perfectly. But when I run it on Windows, I get this error.

This is the part of CMake code that does the linking:

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG") add_executable(rddl-parser ${RDDL_PARSER_SOURCES} ${FLEX_scanner_OUTPUTS} ${BISON_parser_OUTPUTS}) target_link_libraries(rddl-parser ${FLEX_LIBRARIES} ${BISON_LIBRARIES})

The option to copy the definition of the function to the source file is a no go.

Đorđe Relić
  • 418
  • 4
  • 13
  • please post a [mcve] – m.s. Jan 02 '17 at 14:22
  • @m.s. I tried to include more context. The project really big and this is the best I could do while keeping it short and simple. – Đorđe Relić Jan 02 '17 at 14:58
  • where is `State(std::vector const& cpfs)` implemented? you should really try to strip down your project by removing as much as possible to nail down the issue. – m.s. Jan 02 '17 at 15:02
  • Like I wrote, defined (or rather implemented) in `states.h` and used in `preprocessor.cc`. The issue is in the CMake code I believe. There is something I'm missing but cannot realize what. – Đorđe Relić Jan 02 '17 at 15:15
  • the linker error is about `State(std::vector const&)`, NOT `State(int)`. This constructor is NOT defined in the code you pasted. – m.s. Jan 02 '17 at 15:17
  • Corrected. Thank your patience and help correcting the question. – Đorđe Relić Jan 02 '17 at 15:28
  • is `states.cc` actually compiled and linked into the binary? it must be in either `${RDDL_PARSER_SOURCES}`, `${FLEX_scanner_OUTPUTS}` or `${BISON_parser_OUTPUTS}`. Does `states.cc` appear in any of those variables if you output them (e.g. using (`message(STATUS "${RDDL_PARSER_SOURCES}")`? – m.s. Jan 02 '17 at 15:41
  • Yes, `states.cc` is compiled. I took a screenshot of the compilation results and [pasted it on imgur](http://imgur.com/ZaeWonf). – Đorđe Relić Jan 02 '17 at 20:55
  • can you upload states.cc to gist as well? – m.s. Jan 03 '17 at 11:43
  • [`states.cc`]( https://gist.github.com/DjoleR/5e201942ba20591809025d98c6eaf400) [`states.h`] (https://gist.github.com/DjoleR/a2e08a9a83d5a3cc0247c0d431e87093) – Đorđe Relić Jan 03 '17 at 16:10

2 Answers2

0

OK, there was some almost duplicate code in this project where I noted that State was defined as struct and not as a class. When I switched it to being defined as class with all public methods, the compilation passed. It's interesting that this wasn't an issue on Unix and is on Windows.

Đorđe Relić
  • 418
  • 4
  • 13
-1

Check whether the declaration of the function/class match exactly their definitions. It could happen that when you compile logical_expressions.cc you define something that is not identical to the forward declaration for preprocessor.cc and rddl.cc files.

Luca Cappa
  • 1,925
  • 1
  • 13
  • 23
  • The code works on Unix without any modifications to class names, so that is not the problem. – Đorđe Relić Jan 02 '17 at 14:37
  • if you already checked and excluded declaration/definition matching problems, that's fine. Then it could be possible that your states.cc translation unit is not included at link time. Could you please augment verbosity setting to true CMAKE_VERBOSE_MAKEFILE and then reconfigure and rebuild using cmake? Post the build log on a [gist](https://gist.github.com/), thanks. – Luca Cappa Jan 02 '17 at 16:03
  • Done that, here's the build log https://gist.github.com/DjoleR/bc725600c7de6d3e7ef8a673583ee6f4 – Đorđe Relić Jan 03 '17 at 10:51
  • Could you please set CMAKE_VERBOSE_MAKEFILE to True (e.g just putting a check near that name on the variables list of CMake-Gui), then reconfiguring and generate again the project files. Then run by command line: "cmake --build ." where the current working directory is the root directory where you generated the project files (aka build directory set in cmake-gui). Then you should get a verbose output containing all the invocation with arguments passed to the msvc (i.e. cl.exe and link.exe). Looking to the log it will be possible to track if any .obj is missing during linking. – Luca Cappa Jan 03 '17 at 12:42
  • I've set `set(CMAKE_VERBOSE_MAKEFILE True)` but I don't have any more detailed output than I pasted on gist. Can't find anything else in CMakeCache nor CMakeOutputLog. But, if it's compiled successfully with other files (which are linked) how could a problem there? I even changed the ordering of the compilation of the files in case that made a difference but it didn't. – Đorđe Relić Jan 03 '17 at 16:17
  • eventually the problem was what I described: a mismatch of the declaration/definition. Nice you found out! Next time it is the first thing you need to do. Also, being able to create a verbose output is fundamental for any wanna be developer. – Luca Cappa Jan 03 '17 at 17:19
  • In a way yes, your comment was correct, but the key error was in the *type* of the word, not a typo or incorrect name. In my opinion, the output was detailed enough, it was just a stupid and strange error. – Đorđe Relić Jan 03 '17 at 18:38