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

Linking static libraries #92

Closed
nturumel opened this issue Mar 6, 2019 · 15 comments
Closed

Linking static libraries #92

nturumel opened this issue Mar 6, 2019 · 15 comments

Comments

@nturumel
Copy link

nturumel commented Mar 6, 2019

Expected Behavior

Please tell us what you expected to happen. If possible, include some sample code for us to reproduce what you're seeing.

Actual Behavior

What happened instead? If you have a screenshot or stack trace of the error, please attach it.

Cevelop Version, Operating System and Compiler

The more we know about your setup, the easier it will be for us to reproduce the problem.

@nturumel
Copy link
Author

nturumel commented Mar 6, 2019

i have a static library .a file that I created, I want to add it to another project, what should I do?
Currently I copy it to the project and then goto properties, C++ build options and add a library there, in the library path option, however, it gives me a
-lC://.... cannot locate sample.a file, even though it is there. Is it a parsing problem?

@tonisuter
Copy link

Hi

There are two ways you can do this in Cevelop. If the library is a separate Cevelop project in the same workspace, you can do the following:

  1. Open the properties of the executable project.

  2. Go to C/C++ General -> Paths and Symbols -> References

  3. Add a reference to the library project. This will automatically set the library path, header path, etc.

The end result should look like this:
bildschirmfoto 2019-03-07 um 10 36 17

If you instead want to add the library and its header files directly to the executable project, you can do that as well. However, this means that you need to manually specify the library path, library name, etc:

  1. Open the properties of the executable project.

  2. Go to C/C++ General -> Paths and Symbols -> Library Paths and add the path to the library as a workspace path.
    bildschirmfoto 2019-03-07 um 10 47 53

  3. Go to C/C++ General -> Paths and Symbols -> Libraries and add the name of the library (without the lib prefix and the .a file extension).
    bildschirmfoto 2019-03-07 um 10 47 59

I hope this fixes your problem. Otherwise, please let us know.

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019

I tried to do that, but I still have issues, as I mentioned before I need to link the lib.a file in this case libSignalStatisticsLibNihar.a file and the header file to my executable, even if it means to copy both the .hpp and the .a to the executable folder, can you help me with it?

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019

1- this is the library header and the executable
2- added reference
3-built
4-run config
5-run failed

@PeterSommerlad
Copy link

Your build went perfectly. And since it is a static library it will be included in your exe file.

What might be missing is the compiler's run-time library (DLL). Depending if you are using g++ on windows through cygwin or mingw different reasons might be the case. Can you run the exe in a command prompt window. If it is cygwin, does it run in cygwn's bash, if it you are using mingw can you run it in a regular command prompt. You might need to add the compiler's runtime DLL's location to your path. I remember from 10+ years ago, it was recommended for Cygwin users to copy the cygwin DLL into the WINDOWS directory to have it always available.

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019

image

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019

I think there might be something else, is there a way to use just the header and the archive of the library and hide the implementation?

@PeterSommerlad
Copy link

So, your program linked just fine, but does neither run from Cevelop nor from the command line.

did your test your compiler's installation on your windows computer by itself, e.g. by compiling a simple hello world c++ program with it. if that does run, then there might be something.

However, to further diagnose, I suggest that you provide more information about your windows and g++ setup, because the problem definitely does not seem to be rooted in Cevelopl, but in your underlying compilation/execution setup.

You are using the 32 bit command prompt. May be your program was compiled for 64 bit.

  1. What Windows Version are you using (version, 32 or 64 bit)

  2. What compiler (version) are you using for compilation (cygwin/mingw, 32/64bit, version of g++)?

  3. Can you compile and run a minimal C++ program?

Otherwise, everything is just speculation.

BTW, you should have provided all that information when you initially filed the bug

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019 via email

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019 via email

@PeterSommerlad
Copy link

can you do that from Cevelop? Or only on the command line? Again, which g++ are you using?

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019

Thank You, I can run a sample file from cevelop, not from my terminal, I am sing mingw 0.6.3, is there any way I can upload my executable project folder and have someone help me please?

@PeterSommerlad
Copy link

The problem you are having is definitely a 32/64 bit problem, if my google foo is not wrong and has nothing to do with Cevelop. If you can not provide the information I asked for, I can not be of further help. I won't debug your executable (which I doubt is the problem). I expect everything you are running is 64bit. But may be the option set in your mingw compilation targets 32 bit and such a program might not run on your system or vice versa.

@PeterSommerlad
Copy link

we usually recommend our students to use https://nuwen.net/mingw.html installation. However, this requires some adjustments (see cevelop FAQ), so that Eclipse CDT detects the compiler. current is Version 6. if your version number is correct it seems very old, it might be just that the .exe generated is not compatible with your windows version.

@nturumel
Copy link
Author

nturumel commented Mar 7, 2019

Thank you for your help, I understand as, I am operating on a 64 bit os, and I am using the mingw 0.6.3, I will take a look at the link you sent me

@Darnor Darnor closed this as completed Aug 12, 2019
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

4 participants