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

Fix C++ client cannot be built on Windows #10363

Merged

Conversation

BewareMyPower
Copy link
Contributor

Motivation

C++ source code cannot be built on Windows. The build commands are:

> cmake -B _builds -S . `
  -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF
> cmake --build .\_builds\

There're two errors. One is

pulsar-client-cpp\lib\ReaderImpl.h(34): error C2144: syntax error: 'int' should be preceded by ';'
...

It's because PULSAR_PUBLIC is __declspec(dllexport) on Windows platform and it should be put before the variable type.

The other error is

LINK : fatal error LNK1104: cannot open file 'pulsar.lib' pulsar\pulsar-client-cpp_builds
\examples\SampleReaderCApi.vcxproj]
...

It looks like when files under examples and perf directories were compiled, it tried to link pulsar.lib and CMake target pulsarShared's name has a dll suffix, like pulsardll.lib and pulsardll.dll. The suffix is redundant.

Modifications

  • Put PULSAR_PUBLIC before the variable type.
  • Keep the LIB_NAME as the shared library's name, i.e. remove the dll suffix.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

@BewareMyPower
Copy link
Contributor Author

Currently there's no CI build process for Windows. It's different from Unix systems that could install a compiler easily. Also I'm not familiar with how to install the necessary softwares using pure commands on Windows.

I built Pulsar C++ client on Windows with CMake 3.20 and Visual Studio 2019 Community, though I didn't use the IDE directly but only use CMake to detect the Windows C++ compiler behind the IDE.

@BewareMyPower
Copy link
Contributor Author

I think we can release the C++ client to some existed package manager. I see https://github.com/edenhill/librdkafka uses NuGet for package management. Also I think https://github.com/microsoft/vcpkg is good.

@lhotari
Copy link
Member

lhotari commented Apr 25, 2021

/pulsarbot run-failure-checks

@codelipenghui codelipenghui merged commit 8fed161 into apache:master Apr 26, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-cpp-windows-build branch April 26, 2021 00:59
codelipenghui pushed a commit that referenced this pull request Apr 26, 2021
### Motivation

C++ source code cannot be built on Windows. The build commands are:

```powershell
> cmake -B _builds -S . `
  -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF
> cmake --build .\_builds\
```

There're two errors. One is

> pulsar-client-cpp\lib\ReaderImpl.h(34): error C2144: syntax error: 'int' should be preceded by ';'
> ...

It's because `PULSAR_PUBLIC` is `__declspec(dllexport)` on Windows platform and it should be put before the variable type.

The other error is

> LINK : fatal error LNK1104: cannot open file 'pulsar.lib' pulsar\pulsar-client-cpp\_builds
\examples\SampleReaderCApi.vcxproj]
> ...

It looks like when files under `examples` and `perf` directories were compiled, it tried to link `pulsar.lib` and CMake target `pulsarShared`'s name has a `dll` suffix, like `pulsardll.lib` and `pulsardll.dll`. The suffix is redundant.

### Modifications

- Put `PULSAR_PUBLIC` before the variable type.
- Keep the `LIB_NAME` as the shared library's name, i.e. remove the `dll` suffix.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

(cherry picked from commit 8fed161)
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants