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

Compile with MinGW-64 (G++) #66

Open
ryanwe1ss opened this issue Feb 19, 2022 · 4 comments
Open

Compile with MinGW-64 (G++) #66

ryanwe1ss opened this issue Feb 19, 2022 · 4 comments
Milestone

Comments

@ryanwe1ss
Copy link

Hi fpagliughi,

Would you happen to know how to compile a sockpp included CPP file properly with G++? I've tried many including:
g++ main.cpp -o main -I "sockpp/include/" -L "sockpp/build/Debug/sockpp-static.lib"

Including both the path and the linker file location. The program compiles properly when I have the actual include statement (example: #include <sockpp/tcp_connector.h>) only - but when trying to add a TCP connector (example: sockpp::tcp_connector conn({"localhost", 12345});) - it fails to compile.

@fpagliughi
Copy link
Owner

What platform are you trying this on? From the ".lib" I would assume a flavor of Windows?

I don't know Windows very well, and what limited experience I have with it is all with MSVC. So I'm not sure how much I can help. But...

It appears that you're working out of a build tree without installing it. In that case, the include files are not where you might expect. After install, the tree might look like:

usr
└── local
    ├── bin
    ├── include
    │   └── sockpp
    └── lib

So there's an include/sockpp (not just an include)
So on the command line, you tell it to look in include ( -I /usr/local/include )
And in the source, you specify to look in a sockpp subdirectory: ( #include <sockpp/tcp_connector.h> )

Then, in Linux, the g++ switch '-L' tells the linker where to look for files, but the '-l' (lower-case L) tells it the library files. I would assume MinGW does the same?

So, all together, the command line is:

$ g++ tcpecho.cpp -o tcpecho -I /my/install/path/include -L /my/install/path/lib -lsockpp

@ryanwe1ss
Copy link
Author

Yeah, i'm trying to compile it in windows in order to run on it which I am using as a client where I connect to it from a linux server.

I'm pretty sure it should be very similar due to my experience using the MinGW compiler on both windows and linux being about the same in terms of command line parameters.

I'll give that command a try in a bit, just out at the moment but thank you very much otherwise for your feedback!

@ryanwe1ss
Copy link
Author

ryanwe1ss commented Feb 19, 2022

So I tried running this compile command:
g++ main.cpp -o main -I "sockpp/include/" -L "sockpp/lib/sockpp-static.lib" -lsockpp

But my G++ compiler was unable to identify what "-lsockpp" is, outputting: cannot find -lsockpp (returned 1 exit status) on Windows. I was able to get it to work on Visual C++ but I couldn't get it to compile in release mode so it would not have to require the microsoft DLL's such as MSVCP140D.dll on any computer is runs on (self-contained). But so far this MinGW compiler I am using on Windows is installed the same way as it would be on linux and works as intended.

It is definitely a bit trickier on windows to perform these types of tasks but would you know how I could get MinGW to recognize what -lsockpp is?

@fpagliughi fpagliughi added this to the v0.8.1 milestone Jan 18, 2023
@fpagliughi
Copy link
Owner

fpagliughi commented Jan 18, 2023

Sorry I never got back to this. I kept trying to figure out networking on Windows with MinGW, but I couldn't figure out the way different versions of the compiler define different macros. Like some versions seem to define _WIN32 and others don't?

So I gave up. Windows isn't a huge priority for me, and just getting MSVC working was enough of a chore. If you figured it out, let me know. I'm happy to put up instructions in the README or take whatever PR to make it work.

But, for completeness, with gcc, -L typically tells it where to look, so give that a directory. And -l tells it what library to link, with just the base file name, no extension. So in your case, together, it should just be:

g++ main.cpp -o main -I "sockpp/include" -L "sockpp/lib" -lsockpp-static

@fpagliughi fpagliughi modified the milestones: v0.8.1, v0.9 Jan 30, 2023
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

2 participants