Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling on windows using visual Studio #55

Closed
ghost opened this issue Apr 10, 2018 · 12 comments
Closed

Compiling on windows using visual Studio #55

ghost opened this issue Apr 10, 2018 · 12 comments

Comments

@ghost
Copy link

ghost commented Apr 10, 2018

Hi , i want to use this parser in a project we are currently working on.

We are developing on windows and use visual studio, i have always been the IDE guy so i have no idea how makefiles work i tried to create a project adding the files (following my understanding of the makefile - yes i did some reading on makefiles-) but i can't get it to work.

if i understand correctly , there are 2 libraries one is core and the second is the builtin fuctions so i need to create the first .lib file using the files of the core, then compile the built-in-features library that is dependent on the core one.

and of course there is the testing file.

i hope it's not too much to ask, i really like the project and it fits perfectly for my needs specially the fact that i can augment it with my own features.

Thank you in advance.

@VinGarcia
Copy link
Member

VinGarcia commented Apr 10, 2018

Hello @grazba, the compiling process is as you described but there are some details that might help you:

  1. You don't need to compile the files test-shunting-yard.cpp and catch.cpp they are used for testing when adding new features to the library itself.
  2. The core-shunting-yard.o binary is formed by compiling the following files into a single file:
  • shunting-yard.cpp
  • packToken.cpp
  • functions.cpp
  • containers.cpp
  1. The built-in features is composed only by the builtin-features.cpp file. This file is actually very simple, it just includes several files from the directory builtin-features, it exists only to simplify the building process.

I noticed that the Makefile includes the core files when building the release version of builtin-features.o, this seems to be a mistake on my part since it is not required I will remove it now and commit the change.

So although I am not experienced with Visual Studio, I bet you could just include all the files I mentioned when creating the libraries. The reason for creating 2 .o files is so it is easier to remove the builtin-features if you don't like them and prefer to implement everything. If you are not planing on removing any of the existing built-in features you could compile all these .cpp files into a single library.

@VinGarcia
Copy link
Member

Also there is a difference between a .dll which is a Shared Library and an Object file. I actually never needed to use a Shared Library myself, the .o the Makefile create are just a precompiled version of the .cpp files meant to be included in your compilation process, but they could be replaced by the original .cpp files with no loss.

The only requirement they might need to work is for the compiler to be compatible with C++11 standard. In GCC this is made by adding a flag to the compiler: -std=c++11

I hope this is helpful, I will be available if you have any other doubts =]

@ghost
Copy link
Author

ghost commented Apr 11, 2018

Thank you for your answers, it helped a lot !

I had an issue with ref-qualifiers (not supported by the compiler we're using).
i compiled it in a static library successfully thank you very much.

@ghost ghost closed this as completed Apr 11, 2018
@ghost
Copy link
Author

ghost commented Apr 11, 2018

Hi again , so i have to reopen this one ^^ !

So i did get it work, but the built in features are not there, i added the builtin-features.cpp file to the project and even added the headers to it as well just for good measure.

But for a reason the parser can not recognize the operators , if i declare a variable and send it to the parser to evaluate and print it it works fine.

I tried to create another project that uses the first library (the core) and adds the built in features and the results are the same no operators are recognized.

the only things i changed in the source code is adding a header file include for the integer types used (it's necessary on windows) and i deleted the && qualifier (not supported by my compiler).

It should not change how things work (just some memory waste no big deal) or am i wrong ?

thank you again !

@ghost ghost reopened this Apr 11, 2018
@VinGarcia
Copy link
Member

VinGarcia commented Apr 11, 2018

Yes it should not have changed the behavior.

The built-in features are added during static initialization time: On each of the files in builtin-features/ you will find a singleton class being declared, it has no attributes and it is only used to register the operators, reserved words and etc on the global structures that hold them. An example of such class:

class Startup {
  Startup() {
    // access global variables only once at initialization time.
  }

// This name after the class declares an instance of this class (named _Startup)
// at static initialization time making the constructor run only once:
} _Startup;

If they are not running it might mean these constructors are not being executed which might have 2 reasons:

  1. There is some problem when including these files into your code.
  2. Your code is being executed at initialization time, i.e. before main() is executed. If this was the case your compiler could schedule to execute a cparse expression before the operations are registered, but this is an unlikely scenario.

In any case you could confirm if it is being executed by adding a std::cout << "here i am" << std::endl; inside the Startup constructor in the file "builtin-features/operations.h".

If the problem lays in the static initialization order you could replace these Startup classes with a global function that you may call once inside your code. But again this is only if you are initializing static class instances that execute cparse expressions at contruction time, which is an unlikely scenario.

If you find out anything new about this problem tell me, I want it solved as well =]

@ghost
Copy link
Author

ghost commented Apr 11, 2018

well i printed something on each of the constructors to see if the code is even executed and apparently it is not.
I'm trying to understand where/when is the the built-in code executed and i find it odd that the built-in features files do not have any include statements for the core types. You said it is at static initialization time, but most of the structs do not define an instance except one

struct Startup {
Startup() {

	std::cout << "Startup functions !!! \n";
...
}
} base_functions_startup;

i'm thinking about including the adding of features into my code that should help me go forward, but it still bugs me that i can't make it a whole static library that i can use directly in another project.

@VinGarcia
Copy link
Member

Check the file builtin-features.cpp this is the file that include the core headers and then include the files in the builtin-features/ directory.

It is a little confusing but before this change all the builtin-features were kept in a single file whicih was much more complex to read.

@VinGarcia
Copy link
Member

Also if you look carefully all of them declare instances, except the name the instance use is the same as the class name (this is a way of implementing the singleton pattern, since once this instance exist the class name is not acessible by other parts of the code, only the instance).

@VinGarcia
Copy link
Member

VinGarcia commented Apr 11, 2018

I have made some changes on the builtin-features files to improve its readability:

  1. builtin-features/*.h were renamed to builtin-features/*.inc: They are not header files they are cpp files meant for inclusion. According to google style guide for C++ their extension should be .inc.
  2. The Startup class instances had the same name of their classes, but this was confusing, now the name used is "_Startup", so it is more readable.

I am also bugged about why these are not being executed. I am thinking about how to improve this so it won't give you too much trouble to initialize them.

I have an idea of how to do it, tonight I will try to implement it, it should greatly simplify setting up the library without static initialization.

Hopefully this will solve it for you.

@ghost
Copy link
Author

ghost commented Apr 11, 2018

So as i expected if i add the features in my code it works fine ! i'll look more into it to find a way to get everything as a library (or two keeping the original design) and if i get it working i'll share the solution files for visual studio 2013-2015-2017.

looking forward to your changes too , have a good one talk soon.

@VinGarcia
Copy link
Member

Hello @grazba, I was unable to work yesterday night but I just did it.

There is now a new file called cparse/builtin-features.inc.

If you include this file inside your main.cpp file you will be able to call the function cparse_startup() that will initialize all built-in features. An example of this would be:

#include "cparse/builtin-features.inc"

int main() {
  cparse_startup();
  
  // ... Your code goes here ...
}

There is one caveat: If you do include this file you should not include the object file builtin-features.o (it could complain about the redefinition of functions).

Also, you must not include this .inc file more than once or it will also complain about the redefinition of functions.

I liked the way it turned out. If this solves your problem you may mark this issue as solved. I will later update the Wiki so this option is explained to everyone.

@ghost
Copy link
Author

ghost commented Apr 13, 2018

Thanks for the update, this solution is similar to what i'm doing, i have to add features anyways so keeping the built-in features in my project and only using the core as a library is a great solution.

I will close the issue now thank you again !

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant