Skip to content

GH-49538: [C++][FlightRPC][ODBC] Use static linkage in Windows FlightSQL ODBC driver#49585

Open
amoeba wants to merge 53 commits intoapache:mainfrom
amoeba:flight-sql-odbc-static
Open

GH-49538: [C++][FlightRPC][ODBC] Use static linkage in Windows FlightSQL ODBC driver#49585
amoeba wants to merge 53 commits intoapache:mainfrom
amoeba:flight-sql-odbc-static

Conversation

@amoeba
Copy link
Copy Markdown
Member

@amoeba amoeba commented Mar 24, 2026

Rationale for this change

The FlightSQL ODBC driver was previously using dynamic linkage for the Arrow deps it relies on. This worked but prevented a challenge for code signing because (I think) we'd have to sign each DLL and signing costs money. We can use static linkage with a dynamically linked MSVC runtime so we only have one DLL to sign.

Ref: #49404

What changes are included in this PR?

Updates to CMake and CI for the build to allow static linkage with dynamic MSVC runtime (x64-windows-static-md).

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

@github-actions
Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented Mar 24, 2026

I have this building locally. Before this PR:

Dump of file release\arrow_flight_sql_odbc.dll

File Type: DLL

  Image has the following dependencies:

    arrow_flight_sql.dll
    arrow_flight.dll
    WSOCK32.dll
    WS2_32.dll
    CRYPT32.dll
    GDI32.dll
    arrow_compute.dll
    arrow.dll
    abseil_dll.dll
    boost_locale-vc143-mt-x64-1_90.dll
    KERNEL32.dll
    USER32.dll
    COMDLG32.dll
    MSVCP140.dll
    MSVCP140_CODECVT_IDS.dll
    VCRUNTIME140.dll
    VCRUNTIME140_1.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-string-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll
    api-ms-win-crt-convert-l1-1-0.dll
    api-ms-win-crt-filesystem-l1-1-0.dll
    api-ms-win-crt-time-l1-1-0.dll

After:

Dump of file cpp\build\release\arrow_flight_sql_odbc.dll

File Type: DLL

  Image has the following dependencies:

    ADVAPI32.dll
    IPHLPAPI.DLL
    WSOCK32.dll
    GDI32.dll
    WS2_32.dll
    CRYPT32.dll
    KERNEL32.dll
    USER32.dll
    COMDLG32.dll
    bcrypt.dll
    dbghelp.dll

@amoeba amoeba force-pushed the flight-sql-odbc-static branch from 74eb8f6 to 3320df2 Compare March 29, 2026 18:29
@amoeba amoeba force-pushed the flight-sql-odbc-static branch from ca55ec8 to 7782c69 Compare April 11, 2026 05:32
@amoeba amoeba changed the title DRAFT: set up static build of ODBC FlightSQL driver GH-49538: [C++][FlightRPC][ODBC] Use static linkage in Windows FlightSQL ODBC driver Apr 18, 2026
@github-actions
Copy link
Copy Markdown

⚠️ GitHub issue #49538 has been automatically assigned in GitHub to PR creator.

Copy link
Copy Markdown
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc Outdated
@github-actions github-actions Bot added awaiting merge Awaiting merge awaiting review Awaiting review and removed awaiting review Awaiting review labels Apr 19, 2026
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review awaiting merge Awaiting merge labels Apr 20, 2026
Copy link
Copy Markdown
Collaborator

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amoeba I see the branch is about a week old, could we rebase on the latest main? I see there are no conflicts, but I am curious to see if the test code changes at odbc_impl in this PR can incidentally help with #49767 (not required for this PR)

I have tested the ODBC MSI installer manually, and can confirm I am able to retrieve data from Power BI using the installer and static linkage ODBC.

Comment thread cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc Outdated
Copy link
Copy Markdown
Collaborator

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to build and test release ODBC on my Windows machine locally. But I am getting this error on debug:

I have built from scratch and kept getting this error after several tries. I think this error was from a pre-existing issue where static Debug mode on MSVC was not supported.

absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (?Dtor
@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(grpc_client.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\arrow-flight-sql-test.vcxproj]
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\arrow-flight-sql-test.exe : 
fatal error LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\arrow-flight-sql-test.vcxproj]
  Building Custom Rule C:/path/to/arrow/cpp/src/arrow/flight/CMakeLists.txt
  test_server.cc
absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (?Dtor
@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(protocol_grpc_internal.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\flight-test-server.vcxproj]
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\flight-test-server.exe : fatal error
LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\flight-test-server.vcxproj]

(and many errors that look similar)

Since #48964 changes absl bundling, maybe rebasing to main will fix this error on debug static builds.

Co-authored-by: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
@amoeba amoeba force-pushed the flight-sql-odbc-static branch from 1f8181f to 56ca928 Compare April 21, 2026 23:52
@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented Apr 21, 2026

Thanks for testing @alinaliBQ. I just rebased and I'll try a debug build locally and report back.

@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented Apr 22, 2026

I was able to reproduce the issue in debug mode. So far I've tried to address the duplicated symbols by only linking to gRPC::grpc++ from flight_testing when linking dynamically which didn't work.

@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented Apr 22, 2026

I pushed a workaround in 2b48b4f. @alinaliBQ would you be able to double check for me?

Copy link
Copy Markdown
Collaborator

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amoeba Thanks! The workaround 2b48b4f worked for the executables (such as flight-test-server) mentioned in it. However in the static Debug build, I see the following items are still affected with LNK1169:

  • arrow_flight.dll
  • arrow-odbc-spi-impl-test.exe
  • arrow_odbc_spi_impl_cli.exe
  • flight-sql-test-app.exe
  • flight-sql-test-server.exe

I think if we also add these above executables to the workaround, it might fix the issue.

Today I am able to build and test the dynamic debug build successfully, so folks can still test using the dynamic debug build. As the static debug build issue (both tests + flight.dll) is likely pre-existing, I’m good if folks can address this in a follow-up PR, and particularly the build issue with arrow_flight.dll might be trickier to fix.

absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (
?Dtor@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(grpc_client.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\odbc\odbc_impl\arrow-odbc-spi-impl-test.v
cxproj]
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\arrow-odbc-spi-impl-test.exe : f
atal error LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp
\static-debug-build\src\arrow\flight\sql\odbc\odbc_impl\arrow-odbc-spi-impl-test.vcxproj]
...
absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (
?Dtor@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in grpc_client.obj [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\arrow_flight_shared.vcxproj]
     Creating library C:/path/to/arrow/cpp/static-debug-build/debug/Debug/arrow_flig
  ht.lib and object C:/path/to/arrow/cpp/static-debug-build/debug/Debug/arrow_flight
  .exp
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\arrow_flight.dll : fatal error L
NK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\static-debu
g-build\src\arrow\flight\arrow_flight_shared.vcxproj]
...
absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (
?Dtor@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(grpc_client.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\odbc\odbc_impl\arrow_odbc_spi_impl_cli.vc
xproj]
C:\path\to\arrow\cpp\static-debug-build\Debug\bin\arrow_odbc_spi_impl_cli.exe : fata
l error LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\st
atic-debug-build\src\arrow\flight\sql\odbc\odbc_impl\arrow_odbc_spi_impl_cli.vcxproj]
  Building Custom Rule C:/path/to/arrow/cpp/src/arrow/flight/sql/CMakeLists.txt
  test_app_cli.cc
absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (
?Dtor@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(grpc_client.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\flight-sql-test-app.vcxproj]
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\flight-sql-test-app.exe : fatal
error LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\stat
ic-debug-build\src\arrow\flight\sql\flight-sql-test-app.vcxproj]
...
absl_synchronization.lib(mutex.cc.obj) : error LNK2005: "private: void __cdecl absl::lts_20250814::Mutex::Dtor(void)" (
?Dtor@Mutex@lts_20250814@absl@@AEAAXXZ) already defined in arrow_flight_static.lib(protocol_grpc_internal.obj) [C:\path\to\arrow\cpp\static-debug-build\src\arrow\flight\sql\flight-sql-test-server.vcxproj
]
C:\path\to\arrow\cpp\static-debug-build\debug\Debug\flight-sql-test-server.exe : fat
al error LNK1169: one or more multiply defined symbols found [C:\path\to\arrow\cpp\s
tatic-debug-build\src\arrow\flight\sql\flight-sql-test-server.vcxproj]

Comment thread testing
Copy link
Copy Markdown
Collaborator

@alinaliBQ alinaliBQ Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we restore the testing folder? I assume the change was unintentional.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was my mistake. Reverted in 6198d8d.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Bryce, looks like testing got changed again, could we fix this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still see testing in the diff? I don't right now but it did happen a few times while I was working last night.

Comment thread cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt Outdated
@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented Apr 23, 2026

I added the FORCE workaround to the other targets and that helped. I started getting:

C:\Users\Bryce\src\apache\arrow\cpp\build\src\arrow/flight/sql/FlightSql.pb.h(1503): warning C4275: non dll-interface class 'google::protobuf::Message' used as base for dll-interface class 'arrow::flight::protocol::sql::TicketStatementQuery'

So I added ignores in 6354135 and that helped.

Copy link
Copy Markdown
Collaborator

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amoeba , I am now able to build and test the debug static build on local MSVC environment. Just have one comment for testing folder. Rest code changes LGTM

Comment thread testing
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Bryce, looks like testing got changed again, could we fix this?

endif()
endforeach()
endif()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lidavidm @raulcd @kou do any of you have any thoughts on this workaround I came up with using Claude? I can dig in more if any of you want.

It makes sense that the duplicate symbol could show up twice with how the build is set up and I can see why this only shows up in Debug builds: https://github.com/abseil/abseil-cpp/blob/master/absl/synchronization/mutex.h#L1197.

The /FORCE:MULTIPLE workaround seems like a heavy fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens despite linking everything statically? Ugh, I guess it is what it is. (Also: is it just me, or do the preprocessor condition and the comment there contradict each other? The symbol is only defined when not building DLL)

@amoeba
Copy link
Copy Markdown
Member Author

amoeba commented Apr 23, 2026

This is basically ready. I've pinged some people in #49585 (comment) so we'll wait on that to merge.

Copy link
Copy Markdown
Collaborator

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Apr 24, 2026
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.

3 participants